From e2c3b954e50aa44291a6f9e8168972bb3b2b461d Mon Sep 17 00:00:00 2001 From: Luoyy <10894778+zishang520@users.noreply.github.com> Date: Thu, 5 Sep 2024 15:55:05 +0800 Subject: [PATCH] Fix nil pointer dereference in socket server close method - 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" --- socket/server.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/socket/server.go b/socket/server.go index 4af2579..da2db52 100644 --- a/socket/server.go +++ b/socket/server.go @@ -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) }