@@ -279,6 +279,9 @@ export async function startNodeHostMcpManager(
279279 const resolveTransport = deps . resolveTransport ?? resolveMcpTransport ;
280280 const descriptors : NodePluginToolDescriptor [ ] = [ ] ;
281281 const lifecycleAbortController = new AbortController ( ) ;
282+ const lifecycleSignal = deps . signal
283+ ? AbortSignal . any ( [ deps . signal , lifecycleAbortController . signal ] )
284+ : lifecycleAbortController . signal ;
282285 const states = new Map < string , NodeHostMcpServerState > (
283286 listEnabledNodeHostMcpServers ( servers ) . map ( ( [ serverName , config ] ) => [
284287 serverName ,
@@ -336,7 +339,13 @@ export async function startNodeHostMcpManager(
336339 } ;
337340
338341 const scheduleRetry = ( state : NodeHostMcpServerState ) : void => {
339- if ( closed || states . get ( state . serverName ) !== state || state . retryTimer || state . current ) {
342+ if (
343+ closed ||
344+ lifecycleSignal . aborted ||
345+ states . get ( state . serverName ) !== state ||
346+ state . retryTimer ||
347+ state . current
348+ ) {
340349 return ;
341350 }
342351 const delayMs = state . retryDelayMs ;
@@ -431,9 +440,9 @@ export async function startNodeHostMcpManager(
431440 return ;
432441 }
433442 try {
434- await connectAndList ( state , lifecycleAbortController . signal ) ;
443+ await connectAndList ( state , lifecycleSignal ) ;
435444 } catch ( error ) {
436- if ( ! closed ) {
445+ if ( ! closed && ! lifecycleSignal . aborted ) {
437446 warn (
438447 `node host MCP server "${ state . serverName } " reconnect failed: ${ formatMcpError ( error ) } ` ,
439448 ) ;
@@ -451,15 +460,15 @@ export async function startNodeHostMcpManager(
451460 session . client ,
452461 session . requestTimeoutMs ,
453462 ( toolName ) => isMcpToolAllowed ( state . config . toolFilter , toolName ) ,
454- AbortSignal . any ( [ lifecycleAbortController . signal , session . abortController . signal ] ) ,
463+ AbortSignal . any ( [ lifecycleSignal , session . abortController . signal ] ) ,
455464 ) ;
456465 if ( closed || state . current !== session ) {
457466 return ;
458467 }
459468 state . listedTools = tools ;
460469 rebuildDescriptors ( ) ;
461470 } catch ( error ) {
462- if ( closed || state . current !== session ) {
471+ if ( closed || lifecycleSignal . aborted || state . current !== session ) {
463472 return ;
464473 }
465474 warn (
@@ -472,7 +481,13 @@ export async function startNodeHostMcpManager(
472481 } ;
473482
474483 function requestRefresh ( state : NodeHostMcpServerState , session : NodeHostMcpSession ) : void {
475- if ( closed || state . current !== session || ! session . connected || state . refreshQueued ) {
484+ if (
485+ closed ||
486+ lifecycleSignal . aborted ||
487+ state . current !== session ||
488+ ! session . connected ||
489+ state . refreshQueued
490+ ) {
476491 return ;
477492 }
478493 state . refreshQueued = true ;
@@ -482,19 +497,16 @@ export async function startNodeHostMcpManager(
482497 } ) ;
483498 }
484499
485- const startupSignal = deps . signal
486- ? AbortSignal . any ( [ deps . signal , lifecycleAbortController . signal ] )
487- : lifecycleAbortController . signal ;
488500 const tasks = Array . from ( states . values ( ) , ( state ) => async ( ) => {
489501 if ( state . config . auth === "oauth" || state . config . oauth ) {
490502 states . delete ( state . serverName ) ;
491503 warn ( `node host MCP server "${ state . serverName } " skipped: OAuth is not supported` ) ;
492504 return ;
493505 }
494506 try {
495- await connectAndList ( state , startupSignal ) ;
507+ await connectAndList ( state , lifecycleSignal ) ;
496508 } catch ( error ) {
497- if ( ! startupSignal . aborted ) {
509+ if ( ! lifecycleSignal . aborted ) {
498510 warn ( `node host MCP server "${ state . serverName } " failed: ${ formatMcpError ( error ) } ` ) ;
499511 }
500512 }
0 commit comments