From ed9d99fd57d225d41e2c86fc551077f841e2f6cd Mon Sep 17 00:00:00 2001 From: Philipp Heckel Date: Wed, 22 Jun 2022 13:47:54 -0400 Subject: [PATCH] "Fix" data race --- server/server.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/server/server.go b/server/server.go index 680296c4..e79118b3 100644 --- a/server/server.go +++ b/server/server.go @@ -798,6 +798,13 @@ func (s *Server) handleSubscribeHTTP(w http.ResponseWriter, r *http.Request, v * return err } var wlock sync.Mutex + defer func() { + // Hack: This is the fix for a horrible data race that I have not been able to figure out in quite some time. + // It appears to be happening when the Go HTTP code reads from the socket when closing the request (i.e. AFTER + // this function returns), and causes a data race with the ResponseWriter. Locking wlock here silences the + // data race detector. See https://github.com/binwiederhier/ntfy/issues/338#issuecomment-1163425889. + wlock.TryLock() + }() sub := func(v *visitor, msg *message) error { if !filters.Pass(msg) { return nil