Skip to content

Commit

Permalink
fix(network): overriding _readableState causes weird bugs of process …
Browse files Browse the repository at this point in the history
…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.
  • Loading branch information
H4ad committed Apr 2, 2022
1 parent 8bf07eb commit e3c46bc
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 6 deletions.
3 changes: 0 additions & 3 deletions src/network/request.ts
Expand Up @@ -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);
Expand Down
1 change: 0 additions & 1 deletion test/core/base-handler.spec.ts
Expand Up @@ -127,7 +127,6 @@ describe(BaseHandler.name, () => {
adapterRequest.remoteAddress,
);

expect(request.readableEnded).toBe(true);
expect(response).toBeInstanceOf(ServerlessResponse);
});
});
2 changes: 0 additions & 2 deletions test/network/request.spec.ts
Expand Up @@ -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);
Expand All @@ -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);
});

Expand Down

0 comments on commit e3c46bc

Please sign in to comment.