fix: address review-work round 2 findings
- MCP teardown race: add shutdownGeneration counter to prevent in-flight connections from resurrecting after disconnectAll - MCP multi-key disconnect race: replace disconnectedSessions Set with generation-based Map to track per-session disconnect events - MCP clients: check shutdownGeneration in stdio/http client creators before inserting into state.clients - BackgroundManager: call clearTaskHistoryWhenParentTasksGone after timer-based task removal in scheduleTaskRemoval and notifyParentSession - BackgroundManager: clean completedTaskSummaries when parent has no remaining tasks - Plugin dispose: remove duplicate tmuxSessionManager.cleanup call since BackgroundManager.shutdown already handles it via onShutdown
This commit is contained in:
@@ -14,6 +14,7 @@ function getStdioCommand(config: ClaudeCodeMcpServer, serverName: string): strin
|
||||
|
||||
export async function createStdioClient(params: SkillMcpClientConnectionParams): Promise<Client> {
|
||||
const { state, clientKey, info, config } = params
|
||||
const shutdownGenAtStart = state.shutdownGeneration
|
||||
|
||||
const command = getStdioCommand(config, info.serverName)
|
||||
const args = config.args ?? []
|
||||
@@ -55,6 +56,12 @@ export async function createStdioClient(params: SkillMcpClientConnectionParams):
|
||||
)
|
||||
}
|
||||
|
||||
if (state.shutdownGeneration !== shutdownGenAtStart) {
|
||||
try { await client.close() } catch {}
|
||||
try { await transport.close() } catch {}
|
||||
throw new Error(`MCP server "${info.serverName}" connection completed after shutdown`)
|
||||
}
|
||||
|
||||
const managedClient = {
|
||||
client,
|
||||
transport,
|
||||
|
||||
Reference in New Issue
Block a user