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.
This commit is contained in:
Simon Ser 2021-12-08 15:00:02 +01:00
parent 9caa6f9ca0
commit d21fc06d88

View File

@ -286,9 +286,6 @@ func (s *Server) addUserLocked(user *User) *user {
if err := recover(); err != nil { if err := recover(); err != nil {
s.Logger.Printf("panic serving user %q: %v\n%v", user.Username, err, debug.Stack()) s.Logger.Printf("panic serving user %q: %v\n%v", user.Username, err, debug.Stack())
} }
}()
u.run()
s.lock.Lock() s.lock.Lock()
delete(s.users, u.Username) delete(s.users, u.Username)
@ -297,6 +294,9 @@ func (s *Server) addUserLocked(user *User) *user {
s.stopWG.Done() s.stopWG.Done()
}() }()
u.run()
}()
return u return u
} }