mirror of
https://github.com/mattermost/mattermost.git
synced 2025-02-25 18:55:24 -06:00
MM-26571: Move the semaphore creation before hub start (#14938)
This avoids the race of assigning the sema field from the start method
which runs in a goroutine.
The race that happens is
==================
WARNING: DATA RACE
Write at 0x00c003a9d1b0 by goroutine 67:
github.com/mattermost/mattermost-server/v5/app.(*PushNotificationsHub).start()
/home/agniva/mattermost/mattermost-server/app/notification_push.go:264 +0x90
Previous read at 0x00c003a9d1b0 by goroutine 69:
github.com/mattermost/mattermost-server/v5/app.(*Server).createPushNotificationsHub()
/home/agniva/mattermost/mattermost-server/app/notification_push.go:260 +0x1d5
This commit is contained in:
@@ -255,14 +255,13 @@ func (s *Server) createPushNotificationsHub() {
|
||||
notificationsChan: make(chan PushNotification, buffer),
|
||||
app: fakeApp,
|
||||
wg: new(sync.WaitGroup),
|
||||
sema: make(chan struct{}, runtime.NumCPU()*8), // numCPU * 8 is a good amount of concurrency.
|
||||
}
|
||||
go hub.start()
|
||||
s.PushNotificationsHub = hub
|
||||
}
|
||||
|
||||
func (hub *PushNotificationsHub) start() {
|
||||
hub.sema = make(chan struct{}, runtime.NumCPU()*8) // numCPU * 8 is a good amount of concurrency.
|
||||
|
||||
for notification := range hub.notificationsChan {
|
||||
// Adding to the waitgroup first.
|
||||
hub.wg.Add(1)
|
||||
|
||||
Reference in New Issue
Block a user