Add back consumeAndClose functionality. (#7608)
* consume bodies for action button integrations, webrtc gateway, oauth endpoint * Fixing a couple more places, switching to io.Copy to ioutil.Discard, adding a comment to help prevent future performance regressions
Этот коммит содержится в:
коммит произвёл
GitHub
родитель
521e27f4ac
Коммит
3461a7b207
@@ -7,7 +7,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"html"
|
"html"
|
||||||
"html/template"
|
"html/template"
|
||||||
"io/ioutil"
|
|
||||||
"net/http"
|
"net/http"
|
||||||
"net/url"
|
"net/url"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
@@ -701,8 +700,7 @@ func (a *App) sendToPushProxy(msg model.PushNotification, session *model.Session
|
|||||||
} else {
|
} else {
|
||||||
pushResponse := model.PushResponseFromJson(resp.Body)
|
pushResponse := model.PushResponseFromJson(resp.Body)
|
||||||
if resp.Body != nil {
|
if resp.Body != nil {
|
||||||
ioutil.ReadAll(resp.Body)
|
consumeAndClose(resp)
|
||||||
resp.Body.Close()
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_REMOVE {
|
if pushResponse[model.PUSH_STATUS] == model.PUSH_STATUS_REMOVE {
|
||||||
|
|||||||
@@ -685,7 +685,7 @@ func (a *App) AuthorizeOAuthUser(w http.ResponseWriter, r *http.Request, service
|
|||||||
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.token_failed.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else {
|
} else {
|
||||||
ar = model.AccessResponseFromJson(resp.Body)
|
ar = model.AccessResponseFromJson(resp.Body)
|
||||||
resp.Body.Close()
|
consumeAndClose(resp)
|
||||||
|
|
||||||
if ar == nil {
|
if ar == nil {
|
||||||
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, "response_body="+string(bodyBytes), http.StatusInternalServerError)
|
return nil, "", stateProps, model.NewAppError("AuthorizeOAuthUser", "api.user.authorize_oauth_user.bad_response.app_error", nil, "response_body="+string(bodyBytes), http.StatusInternalServerError)
|
||||||
|
|||||||
@@ -676,7 +676,7 @@ func GetOpenGraphMetadata(url string) *opengraph.OpenGraph {
|
|||||||
l4g.Error("GetOpenGraphMetadata request failed for url=%v with err=%v", url, err.Error())
|
l4g.Error("GetOpenGraphMetadata request failed for url=%v with err=%v", url, err.Error())
|
||||||
return og
|
return og
|
||||||
}
|
}
|
||||||
defer res.Body.Close()
|
defer consumeAndClose(res)
|
||||||
|
|
||||||
if err := og.ProcessHTML(res.Body); err != nil {
|
if err := og.ProcessHTML(res.Body); err != nil {
|
||||||
l4g.Error("GetOpenGraphMetadata processing failed for url=%v with err=%v", url, err.Error())
|
l4g.Error("GetOpenGraphMetadata processing failed for url=%v with err=%v", url, err.Error())
|
||||||
@@ -712,7 +712,7 @@ func (a *App) DoPostAction(postId string, actionId string, userId string) *model
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
return model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, "err="+err.Error(), http.StatusBadRequest)
|
||||||
}
|
}
|
||||||
defer resp.Body.Close()
|
defer consumeAndClose(resp)
|
||||||
|
|
||||||
if resp.StatusCode != http.StatusOK {
|
if resp.StatusCode != http.StatusOK {
|
||||||
return model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, fmt.Sprintf("status=%v", resp.StatusCode), http.StatusBadRequest)
|
return model.NewAppError("DoPostAction", "api.post.do_action.action_integration.app_error", nil, fmt.Sprintf("status=%v", resp.StatusCode), http.StatusBadRequest)
|
||||||
|
|||||||
@@ -80,8 +80,7 @@ func (a *App) DoSecurityUpdateCheck() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
bulletins := model.SecurityBulletinsFromJson(res.Body)
|
bulletins := model.SecurityBulletinsFromJson(res.Body)
|
||||||
ioutil.ReadAll(res.Body)
|
consumeAndClose(res)
|
||||||
res.Body.Close()
|
|
||||||
|
|
||||||
for _, bulletin := range bulletins {
|
for _, bulletin := range bulletins {
|
||||||
if bulletin.AppliesToVersion == model.CurrentVersion {
|
if bulletin.AppliesToVersion == model.CurrentVersion {
|
||||||
|
|||||||
@@ -5,6 +5,8 @@ package app
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"crypto/tls"
|
"crypto/tls"
|
||||||
|
"io"
|
||||||
|
"io/ioutil"
|
||||||
"net"
|
"net"
|
||||||
"net/http"
|
"net/http"
|
||||||
"strings"
|
"strings"
|
||||||
@@ -208,3 +210,11 @@ func (a *App) StopServer() {
|
|||||||
a.Srv.GracefulServer = nil
|
a.Srv.GracefulServer = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This is required to re-use the underlying connection and not take up file descriptors
|
||||||
|
func consumeAndClose(r *http.Response) {
|
||||||
|
if r.Body != nil {
|
||||||
|
io.Copy(ioutil.Discard, r.Body)
|
||||||
|
r.Body.Close()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -109,7 +109,7 @@ func (a *App) TriggerWebhook(payload *model.OutgoingWebhookPayload, hook *model.
|
|||||||
if resp, err := utils.HttpClient(false).Do(req); err != nil {
|
if resp, err := utils.HttpClient(false).Do(req); err != nil {
|
||||||
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.event_post.error"), err.Error())
|
l4g.Error(utils.T("api.post.handle_webhook_events_and_forget.event_post.error"), err.Error())
|
||||||
} else {
|
} else {
|
||||||
defer resp.Body.Close()
|
defer consumeAndClose(resp)
|
||||||
webhookResp := model.OutgoingWebhookResponseFromJson(resp.Body)
|
webhookResp := model.OutgoingWebhookResponseFromJson(resp.Body)
|
||||||
|
|
||||||
if webhookResp != nil && webhookResp.Text != nil {
|
if webhookResp != nil && webhookResp.Text != nil {
|
||||||
|
|||||||
@@ -62,7 +62,7 @@ func GetWebrtcToken(sessionId string) (string, *model.AppError) {
|
|||||||
if rp, err := utils.HttpClient(true).Do(rq); err != nil {
|
if rp, err := utils.HttpClient(true).Do(rq); err != nil {
|
||||||
return "", model.NewAppError("WebRTC.Token", "model.client.connecting.app_error", nil, err.Error(), http.StatusInternalServerError)
|
return "", model.NewAppError("WebRTC.Token", "model.client.connecting.app_error", nil, err.Error(), http.StatusInternalServerError)
|
||||||
} else if rp.StatusCode >= 300 {
|
} else if rp.StatusCode >= 300 {
|
||||||
defer rp.Body.Close()
|
defer consumeAndClose(rp)
|
||||||
return "", model.AppErrorFromJson(rp.Body)
|
return "", model.AppErrorFromJson(rp.Body)
|
||||||
} else {
|
} else {
|
||||||
janusResponse := model.GatewayResponseFromJson(rp.Body)
|
janusResponse := model.GatewayResponseFromJson(rp.Body)
|
||||||
|
|||||||
Ссылка в новой задаче
Block a user