From 068b80814b976174e0ad968818281130754f8b9e Mon Sep 17 00:00:00 2001 From: Gusted Date: Mon, 12 Aug 2024 15:31:43 +0200 Subject: [PATCH] [BUG] Make logout event non-blocking - When people click on the logout button, a event is sent to all browser tabs (actually to a shared worker) to notify them of this logout. This is done in a blocking fashion, to ensure every registered channel (which realistically should be one for every user because of the shared worker) for a user receives this message. While doing this, it locks the mutex for the eventsource module. - Codeberg is currently observing a deadlock that's caused by this blocking behavior, a channel isn't receiving the logout event. We currently don't have a good theory of why this is being caused. This in turn is causing that the logout functionality is no longer working and people no longer receive notifications, unless they refresh the page. - This patchs makes this message non-blocking and thus making it consistent with the other messages. We don't see a good reason why this specific event needs to be blocking and the commit introducing it doesn't offer a rationale either. (cherry picked from commit 9c5c08859d8d728da8c5829cf993f4fb308ab1cf) --- modules/eventsource/manager.go | 10 ---------- modules/eventsource/messenger.go | 9 --------- routers/web/auth/auth.go | 2 +- 3 files changed, 1 insertion(+), 20 deletions(-) diff --git a/modules/eventsource/manager.go b/modules/eventsource/manager.go index 7ed2a82903..730cacd940 100644 --- a/modules/eventsource/manager.go +++ b/modules/eventsource/manager.go @@ -77,13 +77,3 @@ func (m *Manager) SendMessage(uid int64, message *Event) { messenger.SendMessage(message) } } - -// SendMessageBlocking sends a message to a particular user -func (m *Manager) SendMessageBlocking(uid int64, message *Event) { - m.mutex.Lock() - messenger, ok := m.messengers[uid] - m.mutex.Unlock() - if ok { - messenger.SendMessageBlocking(message) - } -} diff --git a/modules/eventsource/messenger.go b/modules/eventsource/messenger.go index 6df26716be..378e717126 100644 --- a/modules/eventsource/messenger.go +++ b/modules/eventsource/messenger.go @@ -66,12 +66,3 @@ func (m *Messenger) SendMessage(message *Event) { } } } - -// SendMessageBlocking sends the message to all registered channels and ensures it gets sent -func (m *Messenger) SendMessageBlocking(message *Event) { - m.mutex.Lock() - defer m.mutex.Unlock() - for i := range m.channels { - m.channels[i] <- message - } -} diff --git a/routers/web/auth/auth.go b/routers/web/auth/auth.go index a738de380a..15dad2511a 100644 --- a/routers/web/auth/auth.go +++ b/routers/web/auth/auth.go @@ -408,7 +408,7 @@ func HandleSignOut(ctx *context.Context) { // SignOut sign out from login status func SignOut(ctx *context.Context) { if ctx.Doer != nil { - eventsource.GetManager().SendMessageBlocking(ctx.Doer.ID, &eventsource.Event{ + eventsource.GetManager().SendMessage(ctx.Doer.ID, &eventsource.Event{ Name: "logout", Data: ctx.Session.ID(), })