Browse code

Fix race in LogEvent

Docker-DCO-1.1-Signed-off-by: Alexandr Morozov <lk4d4math@gmail.com> (github: LK4D4)

Alexandr Morozov authored on 2014/06/05 18:35:24
Showing 1 changed files
... ...
@@ -2402,12 +2402,14 @@ func (srv *Server) LogEvent(action, id, from string) *utils.JSONMessage {
2402 2402
 	now := time.Now().UTC().Unix()
2403 2403
 	jm := utils.JSONMessage{Status: action, ID: id, From: from, Time: now}
2404 2404
 	srv.AddEvent(jm)
2405
+	srv.Lock()
2405 2406
 	for _, c := range srv.listeners {
2406 2407
 		select { // non blocking channel
2407 2408
 		case c <- jm:
2408 2409
 		default:
2409 2410
 		}
2410 2411
 	}
2412
+	srv.Unlock()
2411 2413
 	return &jm
2412 2414
 }
2413 2415