diff --git a/package-lock.json b/package-lock.json index d40c9e998..cd1b4b3c4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "testcafe-hammerhead", - "version": "31.6.3", + "version": "31.6.4", "lockfileVersion": 3, "requires": true, "packages": { "": { "name": "testcafe-hammerhead", - "version": "31.6.3", + "version": "31.6.4", "license": "MIT", "dependencies": { "@adobe/css-tools": "^4.3.0-rc.1", diff --git a/package.json b/package.json index 149c77a03..0bfb63506 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "testcafe-hammerhead", "description": "A powerful web-proxy used as a core for the TestCafe testing framework (https://github.com/DevExpress/testcafe).", - "version": "31.6.3", + "version": "31.6.4", "homepage": "https://github.com/DevExpress/testcafe-hammerhead", "bugs": { "url": "https://github.com/DevExpress/testcafe-hammerhead/issues" diff --git a/src/request-pipeline/context/index.ts b/src/request-pipeline/context/index.ts index 695bfee43..44ce23696 100644 --- a/src/request-pipeline/context/index.ts +++ b/src/request-pipeline/context/index.ts @@ -426,6 +426,15 @@ export default class RequestPipelineContext extends BaseRequestPipelineContext { this.goToNextStage = false; } + closeConnectionOnError (): void { + this.req.destroy(); + + // NOTE: For Node versions greater than 15.4, we check the socket. If req.destroy didn't destroy it, we call the corresponding method of the socket. + if (this.req.socket && !this.req.socket.destroyed) + this.req.socket.destroy(); + + } + toProxyUrl (url: string, isCrossDomain: boolean, resourceType: string, charset?: string, reqOrigin?: string, credentials?: urlUtils.Credentials): string { const proxyHostname = this.serverInfo.hostname; const proxyProtocol = this.serverInfo.protocol; diff --git a/src/request-pipeline/utils.ts b/src/request-pipeline/utils.ts index 0e2f0f353..bc9cac9d5 100644 --- a/src/request-pipeline/utils.ts +++ b/src/request-pipeline/utils.ts @@ -90,7 +90,7 @@ export function error (ctx: RequestPipelineContext, err: string) { if (ctx.isPage && !ctx.isIframe) ctx.session.handlePageError(ctx, err); else if (ctx.isAjax) - ctx.req.destroy(); + ctx.closeConnectionOnError(); else ctx.closeWithError(500, err.toString()); }