fix(push): goroutine leak (#540)

This commit is contained in:
Bo-Yi Wu 2020-09-27 12:45:58 +08:00 committed by GitHub
parent e65fc288b6
commit bb18241ce9
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 6 deletions

View File

@ -159,7 +159,7 @@ func GetHuaweiNotification(req PushNotification) (*model.MessageRequest, error)
return nil, err return nil, err
} }
LogAccess.Debug("Default message is %s", string(b)) LogAccess.Debugf("Default message is %s", string(b))
return msgRequest, nil return msgRequest, nil
} }

View File

@ -79,16 +79,18 @@ func pushHandler(c *gin.Context) {
} }
ctx, cancel := context.WithCancel(context.Background()) ctx, cancel := context.WithCancel(context.Background())
notifier := c.Writer.CloseNotify() go func() {
go func(closer <-chan bool) { // Deprecated: the CloseNotifier interface predates Go's context package.
<-closer // New code should use Request.Context instead.
// Change to context package
<-c.Request.Context().Done()
// Don't send notification after client timeout or disconnected. // Don't send notification after client timeout or disconnected.
// See the following issue for detail information. // See the following issue for detail information.
// https://github.com/appleboy/gorush/issues/422 // https://github.com/appleboy/gorush/issues/422
if PushConf.Core.Sync { if PushConf.Core.Sync {
cancel() cancel()
} }
}(notifier) }()
counts, logs := queueNotification(ctx, form) counts, logs := queueNotification(ctx, form)