Skip to content

Commit

Permalink
Fix a Node.js 16 bug that hangs Got streams
Browse files Browse the repository at this point in the history
  • Loading branch information
szmarczak committed Jun 2, 2021
1 parent 6e1d9f9 commit 06a2d3d
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion source/core/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
// Node.js parser is really weird.
// It emits post-request Parse Errors on the same instance as previous request. WTF.
// Therefore we need to check if it has been destroyed as well.
if (response && !response.rawBody && !this._request?.socket?.destroyed) {
//
// Furthermore, Node.js 16 `response.destroy()` doesn't immediately destroy the socket,
// but makes the response unreadable. So we additionally need to check `response.readable`.
if (response?.readable && !response.rawBody && !this._request?.socket?.destroyed) {
// @types/node has incorrect typings. `setEncoding` accepts `null` as well.
response.setEncoding(this.readableEncoding!);

Expand Down

0 comments on commit 06a2d3d

Please sign in to comment.