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

Commit

Permalink
add-remote-tarball: work around node 0.8 http back-pressure bug
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
iarna committed Dec 12, 2015
1 parent d2b7b1e commit 59ed01a
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/cache/add-remote-tarball.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ var path = require('path')
var sha = require('sha')
var retry = require('retry')
var writeStreamAtomic = require('fs-write-stream-atomic')
var PassThrough = require('readable-stream').PassThrough
var npm = require('../npm.js')
var inflight = require('inflight')
var addLocalTarball = require('./add-local-tarball.js')
Expand Down Expand Up @@ -117,6 +118,15 @@ function fetchAndShaCheck (u, tmp, shasum, auth, cb) {
})
})

response.pipe(tarball)
// 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.
response.pipe(PassThrough({highWaterMark: Infinity})).pipe(tarball)
})
}

0 comments on commit 59ed01a

Please sign in to comment.