From bb18241ce9f2d86fb0dad12dfd2169339a4dea00 Mon Sep 17 00:00:00 2001 From: Bo-Yi Wu Date: Sun, 27 Sep 2020 12:45:58 +0800 Subject: [PATCH] fix(push): goroutine leak (#540) --- gorush/notification_hms.go | 2 +- gorush/server.go | 10 ++++++---- rpc/server.go | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/gorush/notification_hms.go b/gorush/notification_hms.go index 1a0f84b..22b23ef 100644 --- a/gorush/notification_hms.go +++ b/gorush/notification_hms.go @@ -159,7 +159,7 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error) return nil, err } - LogAccess.Debug("Default message is %s", string(b)) + LogAccess.Debugf("Default message is %s", string(b)) return msgRequest, nil } diff --git a/gorush/server.go b/gorush/server.go index fb258f9..c659767 100644 --- a/gorush/server.go +++ b/gorush/server.go @@ -79,16 +79,18 @@ func pushHandler(c *gin.Context) { } ctx, cancel := context.WithCancel(context.Background()) - notifier := c.Writer.CloseNotify() - go func(closer <-chan bool) { - <-closer + go func() { + // Deprecated: the CloseNotifier interface predates Go's context package. + // New code should use Request.Context instead. + // Change to context package + <-c.Request.Context().Done() // Don't send notification after client timeout or disconnected. // See the following issue for detail information. // https://github.com/appleboy/gorush/issues/422 if PushConf.Core.Sync { cancel() } - }(notifier) + }() counts, logs := queueNotification(ctx, form) diff --git a/rpc/server.go b/rpc/server.go index f2fe084..4a43c96 100644 --- a/rpc/server.go +++ b/rpc/server.go @@ -63,7 +63,7 @@ func (s *Server) Send(ctx context.Context, in *proto.NotificationRequest) (*prot ThreadID: in.ThreadID, MutableContent: in.MutableContent, Image: in.Image, - Priority: strings.ToLower(in.GetPriority().String()), + Priority: strings.ToLower(in.GetPriority().String()), } if badge > 0 {