Skip to content

Commit

Permalink
Fix nil pointer dereference in socket server close method
Browse files Browse the repository at this point in the history
- Added nil check for s.engine before calling Close() to prevent runtime panic
- Resolved issue where a nil pointer dereference occurred when closing the socket server
- This fixes the error: "runtime error: invalid memory address or nil pointer dereference"
  • Loading branch information
zishang520 authored Sep 5, 2024
1 parent a8d73f2 commit e2c3b95
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion socket/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -602,7 +602,9 @@ func (s *Server) Close(fn func(error)) {
if s.httpServer != nil {
s.httpServer.Close(fn)
} else {
s.engine.Close()
if s.engine != nil {
s.engine.Close()
}
if fn != nil {
fn(nil)
}
Expand Down

0 comments on commit e2c3b95

Please sign in to comment.