From d21fc06d88b9082448db06618fe2fbff5fe9c771 Mon Sep 17 00:00:00 2001 From: Simon Ser Date: Wed, 8 Dec 2021 15:00:02 +0100 Subject: [PATCH] server: cleanup user in defer If a user goroutine panics, this correctly removes it from the global map instead of leaving a dangling entry behind. --- server.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/server.go b/server.go index a1c8774..be4be53 100644 --- a/server.go +++ b/server.go @@ -286,15 +286,15 @@ func (s *Server) addUserLocked(user *User) *user { if err := recover(); err != nil { s.Logger.Printf("panic serving user %q: %v\n%v", user.Username, err, debug.Stack()) } + + s.lock.Lock() + delete(s.users, u.Username) + s.lock.Unlock() + + s.stopWG.Done() }() u.run() - - s.lock.Lock() - delete(s.users, u.Username) - s.lock.Unlock() - - s.stopWG.Done() }() return u