[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 9c5c08859d)
This commit is contained in:
Gusted 2024-08-12 15:31:43 +02:00 committed by forgejo-backport-action
parent 08724823f4
commit 068b80814b
3 changed files with 1 additions and 20 deletions

View file

@ -77,13 +77,3 @@ func (m *Manager) SendMessage(uid int64, message *Event) {
messenger.SendMessage(message) 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)
}
}

View file

@ -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
}
}

View file

@ -408,7 +408,7 @@ func HandleSignOut(ctx *context.Context) {
// SignOut sign out from login status // SignOut sign out from login status
func SignOut(ctx *context.Context) { func SignOut(ctx *context.Context) {
if ctx.Doer != nil { if ctx.Doer != nil {
eventsource.GetManager().SendMessageBlocking(ctx.Doer.ID, &eventsource.Event{ eventsource.GetManager().SendMessage(ctx.Doer.ID, &eventsource.Event{
Name: "logout", Name: "logout",
Data: ctx.Session.ID(), Data: ctx.Session.ID(),
}) })