diff --git a/packages/collector/src/announceCycle/agentHostLookup.js b/packages/collector/src/announceCycle/agentHostLookup.js index a19d6057ed..d6d8c34973 100644 --- a/packages/collector/src/announceCycle/agentHostLookup.js +++ b/packages/collector/src/announceCycle/agentHostLookup.js @@ -119,7 +119,9 @@ function checkHost(host, cb) { } }; + /** @type {import('http').ClientRequest} */ let req; + try { /** * TODO: @@ -173,6 +175,11 @@ function checkHost(host, cb) { } req.on('timeout', function onTimeout() { + if (req.destroyed) { + return; + } + + req.destroy(); handleCallback( new Error(`The attempt to connect to the Instana host agent on ${host}:${agentOpts.port} has timed out`) ); @@ -182,6 +189,11 @@ function checkHost(host, cb) { req.setTimeout(requestTimeout); req.on('error', err => { + if (req.destroyed) { + return; + } + + req.destroy(); handleCallback( new Error( `The attempt to connect to the Instana host agent on ${host}:${agentOpts.port} has failed with the following ` +