File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -260,8 +260,6 @@ func NewTestServer(server *MCPServer, opts ...SSEOption) *httptest.Server {
260260// It sets up HTTP handlers for SSE and message endpoints.
261261func (s * SSEServer ) Start (addr string ) error {
262262 s .mu .Lock ()
263- defer s .mu .Unlock ()
264-
265263 if s .srv == nil {
266264 s .srv = & http.Server {
267265 Addr : addr ,
@@ -274,22 +272,29 @@ func (s *SSEServer) Start(addr string) error {
274272 return fmt .Errorf ("conflicting listen address: WithHTTPServer(%q) vs Start(%q)" , s .srv .Addr , addr )
275273 }
276274 }
275+ srv := s .srv
276+ s .mu .Unlock ()
277277
278- return s . srv .ListenAndServe ()
278+ return srv .ListenAndServe ()
279279}
280280
281281// Shutdown gracefully stops the SSE server, closing all active sessions
282282// and shutting down the HTTP server.
283283func (s * SSEServer ) Shutdown (ctx context.Context ) error {
284- if s .srv != nil {
284+ s .mu .RLock ()
285+ srv := s .srv
286+ s .mu .RUnlock ()
287+
288+ if srv != nil {
285289 s .sessions .Range (func (key , value interface {}) bool {
286290 if session , ok := value .(* sseSession ); ok {
287291 close (session .done )
288292 }
289293 s .sessions .Delete (key )
290294 return true
291295 })
292- return s .srv .Shutdown (ctx )
296+
297+ return srv .Shutdown (ctx )
293298 }
294299 return nil
295300}
You can’t perform that action at this time.
0 commit comments