From e3c46bc7ede4b4aba3304221485c5e0a763eecce Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Vin=C3=ADcius=20Louren=C3=A7o?= Date: Sat, 2 Apr 2022 12:54:41 -0300 Subject: [PATCH] fix(network): overriding _readableState causes weird bugs of process exiting in deadlock When I integrate with NestJS, I could create GET requests but POST requests returned null in response because the NodeJS exits when it could not wait an promise. This bug was caused by request.ts when I override the internal variable of stream _readableState, with this, the NestJS could not process the request and the process exits after some seconds without exit code. --- src/network/request.ts | 3 --- test/core/base-handler.spec.ts | 1 - test/network/request.spec.ts | 2 -- 3 files changed, 6 deletions(-) diff --git a/src/network/request.ts b/src/network/request.ts index 663e5098..10ce5202 100644 --- a/src/network/request.ts +++ b/src/network/request.ts @@ -43,9 +43,6 @@ export class ServerlessRequest extends IncomingMessage { this.url = url; this.ip = remoteAddress; - // ref: https://github.com/nodejs/node/blob/master/lib/internal/streams/readable.js#L1278 - (this as any)._readableState.endEmitted = true; - this._read = () => { this.push(body); this.push(null); diff --git a/test/core/base-handler.spec.ts b/test/core/base-handler.spec.ts index e2ac3724..d90271d9 100644 --- a/test/core/base-handler.spec.ts +++ b/test/core/base-handler.spec.ts @@ -127,7 +127,6 @@ describe(BaseHandler.name, () => { adapterRequest.remoteAddress, ); - expect(request.readableEnded).toBe(true); expect(response).toBeInstanceOf(ServerlessResponse); }); }); diff --git a/test/network/request.spec.ts b/test/network/request.spec.ts index 0e3b31e3..02021427 100644 --- a/test/network/request.spec.ts +++ b/test/network/request.spec.ts @@ -23,7 +23,6 @@ describe('ServerlessRequest', () => { expect(request).toHaveProperty('ip', remoteAddress); expect(request).toHaveProperty('body', body); expect(request).toHaveProperty('complete', true); - expect(request.readableEnded).toBe(true); expect(request).toHaveProperty('httpVersion', '1.1'); expect(request).toHaveProperty('httpVersionMajor', 1); expect(request).toHaveProperty('httpVersionMinor', 1); @@ -32,7 +31,6 @@ describe('ServerlessRequest', () => { expect(request.socket).toHaveProperty('remoteAddress', remoteAddress); expect(request.socket).toHaveProperty('end', NO_OP); expect(request.socket).toHaveProperty('destroy', NO_OP); - expect((request as any)._readableState).toHaveProperty('endEmitted', true); expect(request.socket.address()).toHaveProperty('port', 443); });