Skip to content

Commit

Permalink
fixed OnClose handler panic error
Browse files Browse the repository at this point in the history
  • Loading branch information
PotatoCloud committed Oct 27, 2023
1 parent 18a4e0e commit c03d75b
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion server.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,11 @@ func (s *Server) OnBoot(eng gnet.Engine) gnet.Action {
return gnet.None
}

func (s *Server) OnShutdown(_ gnet.Engine) {}
func (s *Server) OnShutdown(e gnet.Engine) {
if err := e.Stop(s.ctx); err != nil {
s.logger.Errorf("gnet.OnShutdown error: %s", err)
}
}

func (s *Server) OnOpen(c gnet.Conn) ([]byte, gnet.Action) {
s.connNum.Add(1)
Expand All @@ -135,6 +139,9 @@ func (s *Server) OnOpen(c gnet.Conn) ([]byte, gnet.Action) {
}

func (s *Server) OnClose(c gnet.Conn, _ error) gnet.Action {
if c == nil {
return gnet.None
}
s.connNum.Add(-1)
// conn closed, remove conn in monitor list
s.keepConnTable.Delete(c.RemoteAddr().String())
Expand Down

0 comments on commit c03d75b

Please sign in to comment.