From dae9ddc84bf77772df41ea37f10a86fd0dc9642d Mon Sep 17 00:00:00 2001 From: Pavel Date: Mon, 13 Nov 2023 09:46:08 +0400 Subject: [PATCH 1/4] fixed: Sockets hanging --- src/request-pipeline/context/index.ts | 5 +++++ src/request-pipeline/utils.ts | 2 +- 2 files changed, 6 insertions(+), 1 deletion(-) diff --git a/src/request-pipeline/context/index.ts b/src/request-pipeline/context/index.ts index 695bfee43..2b795d143 100644 --- a/src/request-pipeline/context/index.ts +++ b/src/request-pipeline/context/index.ts @@ -426,6 +426,11 @@ export default class RequestPipelineContext extends BaseRequestPipelineContext { this.goToNextStage = false; } + closeConnectionOnError (): void { + if (this.req.socket) + 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()); } From 69b2f26f0c1e83bd94052d37b5ebed8b4c72df4b Mon Sep 17 00:00:00 2001 From: Pavel Date: Tue, 14 Nov 2023 13:43:07 +0400 Subject: [PATCH 2/4] added past solution --- src/request-pipeline/context/index.ts | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/request-pipeline/context/index.ts b/src/request-pipeline/context/index.ts index 2b795d143..c52a3ac6a 100644 --- a/src/request-pipeline/context/index.ts +++ b/src/request-pipeline/context/index.ts @@ -427,8 +427,12 @@ export default class RequestPipelineContext extends BaseRequestPipelineContext { } closeConnectionOnError (): void { - if (this.req.socket) + this.req.destroy(); + + // 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?.destroyed) this.req.socket.destroy(); + } toProxyUrl (url: string, isCrossDomain: boolean, resourceType: string, charset?: string, reqOrigin?: string, credentials?: urlUtils.Credentials): string { From ba5c7857f78ecaea2f99d013a0971c21a1e19545 Mon Sep 17 00:00:00 2001 From: Pavel Date: Wed, 15 Nov 2023 07:30:25 +0400 Subject: [PATCH 3/4] refactor --- src/request-pipeline/context/index.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/request-pipeline/context/index.ts b/src/request-pipeline/context/index.ts index c52a3ac6a..44ce23696 100644 --- a/src/request-pipeline/context/index.ts +++ b/src/request-pipeline/context/index.ts @@ -429,8 +429,8 @@ export default class RequestPipelineContext extends BaseRequestPipelineContext { closeConnectionOnError (): void { this.req.destroy(); - // 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?.destroyed) + // 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(); } From 4d412126c6e57fae6e3103a293bd807a436fa3c3 Mon Sep 17 00:00:00 2001 From: Pavel Date: Thu, 16 Nov 2023 10:48:32 +0400 Subject: [PATCH 4/4] bump version --- package-lock.json | 4 ++-- package.json | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) 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"