File tree Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Expand file tree Collapse file tree 1 file changed +13
-5
lines changed Original file line number Diff line number Diff line change @@ -88,8 +88,10 @@ type StreamableHTTP struct {
8888 logger util.Logger
8989 getListeningEnabled bool
9090
91- initialized chan struct {}
92- sessionID atomic.Value // string
91+ sessionID atomic.Value // string
92+
93+ initialized chan struct {}
94+ initializedOnce sync.Once
9395
9496 notificationHandler func (mcp.JSONRPCNotification )
9597 notifyMu sync.RWMutex
@@ -137,8 +139,12 @@ func (c *StreamableHTTP) Start(ctx context.Context) error {
137139 // For Streamable HTTP, we don't need to establish a persistent connection by default
138140 if c .getListeningEnabled {
139141 go func () {
140- <- c .initialized
141- c .listenForever ()
142+ select {
143+ case <- c .initialized :
144+ c .listenForever ()
145+ case <- c .closed :
146+ return
147+ }
142148 }()
143149 }
144150
@@ -252,7 +258,9 @@ func (c *StreamableHTTP) SendRequest(
252258 c .sessionID .Store (sessionID )
253259 }
254260
255- close (c .initialized )
261+ c .initializedOnce .Do (func () {
262+ close (c .initialized )
263+ })
256264 }
257265
258266 // Handle different response types
You can’t perform that action at this time.
0 commit comments