Skip to content

Commit d9824e7

Browse files
committed
Fixed the deadlock
1 parent 7a1049f commit d9824e7

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

pkg/debugger/client.go

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1075,13 +1075,21 @@ func (c *Client) GetCapturedOutput() *OutputMessage {
10751075
func (c *Client) GetAllCapturedOutput() []OutputMessage {
10761076
var messages []OutputMessage
10771077

1078-
// Collect all available messages without blocking
1079-
for {
1078+
// Non-blocking read of up to 100 messages
1079+
// This prevents clearing the entire channel while still returning available messages
1080+
for i := 0; i < 100; i++ {
10801081
select {
1081-
case msg := <-c.outputChan:
1082+
case msg, ok := <-c.outputChan:
1083+
if !ok {
1084+
// Channel was closed
1085+
return messages
1086+
}
10821087
messages = append(messages, msg)
10831088
default:
1089+
// No more messages available without blocking
10841090
return messages
10851091
}
10861092
}
1093+
1094+
return messages
10871095
}

pkg/mcp/server.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -424,6 +424,9 @@ func (s *MCPDebugServer) Close(ctx context.Context, request mcp.CallToolRequest)
424424
return newErrorResult("failed to close debug session: %v", err), nil
425425
}
426426

427+
// Reinitialize the debug client to ensure it's ready for the next session
428+
s.debugClient = debugger.NewClient()
429+
427430
return mcp.NewToolResultText("Debug session closed successfully"), nil
428431
}
429432

0 commit comments

Comments
 (0)