From 78d44f3eabfb765e5a94df3fda6beb36e0220f50 Mon Sep 17 00:00:00 2001 From: Agniva De Sarker Date: Tue, 23 Jun 2020 00:08:06 +0530 Subject: [PATCH] MM-25701: Reuse HTTP client in sendAckToPushProxy (#14759) We reuse the http client made for push notifications. This leads to reuse of TCP connections rather than creating a new client every time. --- app/notification_push.go | 12 +++++++++--- 1 file changed, 9 insertions(+), 3 deletions(-) diff --git a/app/notification_push.go b/app/notification_push.go index 71ba57593f..5aa6cf0570 100644 --- a/app/notification_push.go +++ b/app/notification_push.go @@ -4,6 +4,8 @@ package app import ( + "io" + "io/ioutil" "net/http" "runtime" "strings" @@ -370,14 +372,18 @@ func (a *App) SendAckToPushProxy(ack *model.PushNotificationAck) error { return err } - resp, err := a.HTTPService().MakeClient(true).Do(request) + resp, err := a.Srv().pushNotificationClient.Do(request) + if err != nil { + return err + } + defer resp.Body.Close() + // Reading the body to completion. + _, err = io.Copy(ioutil.Discard, resp.Body) if err != nil { return err } - resp.Body.Close() return nil - } func (a *App) getMobileAppSessions(userId string) ([]*model.Session, *model.AppError) {