mirror of
https://github.com/anomalyco/opencode.git
synced 2026-05-29 11:14:23 +00:00
fix(mcp): close existing client before reassignment to prevent leaks (#8253)
This commit is contained in:
parent
3600bd27f4
commit
80e1173ef7
1 changed files with 14 additions and 0 deletions
|
|
@ -266,6 +266,13 @@ export namespace MCP {
|
|||
status: s.status,
|
||||
}
|
||||
}
|
||||
// Close existing client if present to prevent memory leaks
|
||||
const existingClient = s.clients[name]
|
||||
if (existingClient) {
|
||||
await existingClient.close().catch((error) => {
|
||||
log.error("Failed to close existing MCP client", { name, error })
|
||||
})
|
||||
}
|
||||
s.clients[name] = result.mcpClient
|
||||
s.status[name] = result.status
|
||||
|
||||
|
|
@ -523,6 +530,13 @@ export namespace MCP {
|
|||
const s = await state()
|
||||
s.status[name] = result.status
|
||||
if (result.mcpClient) {
|
||||
// Close existing client if present to prevent memory leaks
|
||||
const existingClient = s.clients[name]
|
||||
if (existingClient) {
|
||||
await existingClient.close().catch((error) => {
|
||||
log.error("Failed to close existing MCP client", { name, error })
|
||||
})
|
||||
}
|
||||
s.clients[name] = result.mcpClient
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue