Skip to content
This repository was archived by the owner on Aug 11, 2022. It is now read-only.

Commit 94cb05e

Browse files
iarnazkat
authored andcommitted
add-remote-tarball: work around node 0.8 http back-pressure bug
0.8 http streams have a bug, where if they're paused with data in their buffers when the socket closes, they call `end` before emptying those buffers, which results in the entire pipeline ending and thus the point that applied backpressure never being able to trigger a `resume`. We work around this by piping into a pass through stream that has unlimited buffering. The pass through stream is from readable-stream and is thus a current streams3 implementation that is free of these bugs even on 0.8. PR-URL: #10903 Credit: @iarna
1 parent 6541690 commit 94cb05e

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

lib/cache/add-remote-tarball.js

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ var mkdir = require("mkdirp")
55
, sha = require("sha")
66
, retry = require("retry")
77
, writeStreamAtomic = require("fs-write-stream-atomic")
8+
, PassThrough = require('readable-stream').PassThrough
89
, npm = require("../npm.js")
910
, inflight = require("inflight")
1011
, addLocalTarball = require("./add-local-tarball.js")
@@ -105,6 +106,15 @@ function fetchAndShaCheck (u, tmp, shasum, auth, cb) {
105106
})
106107
})
107108

108-
response.pipe(tarball)
109+
// 0.8 http streams have a bug, where if they're paused with data in
110+
// their buffers when the socket closes, they call `end` before emptying
111+
// those buffers, which results in the entire pipeline ending and thus
112+
// the point that applied backpressure never being able to trigger a
113+
// `resume`.
114+
// We work around this by piping into a pass through stream that has
115+
// unlimited buffering. The pass through stream is from readable-stream
116+
// and is thus a current streams3 implementation that is free of these
117+
// bugs even on 0.8.
118+
response.pipe(PassThrough({highWaterMark: Infinity})).pipe(tarball)
109119
})
110120
}

0 commit comments

Comments
 (0)