Skip to content

Commit 06a2d3d

Browse files
committedJun 2, 2021
Fix a Node.js 16 bug that hangs Got streams
1 parent 6e1d9f9 commit 06a2d3d

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed
 

‎source/core/index.ts

+4-1
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,10 @@ export default class Request extends Duplex implements RequestEvents<Request> {
326326
// Node.js parser is really weird.
327327
// It emits post-request Parse Errors on the same instance as previous request. WTF.
328328
// Therefore we need to check if it has been destroyed as well.
329-
if (response && !response.rawBody && !this._request?.socket?.destroyed) {
329+
//
330+
// Furthermore, Node.js 16 `response.destroy()` doesn't immediately destroy the socket,
331+
// but makes the response unreadable. So we additionally need to check `response.readable`.
332+
if (response?.readable && !response.rawBody && !this._request?.socket?.destroyed) {
330333
// @types/node has incorrect typings. `setEncoding` accepts `null` as well.
331334
response.setEncoding(this.readableEncoding!);
332335

0 commit comments

Comments
 (0)
Please sign in to comment.