Commit 1441dc6aaf4517378c3ba5640cf67739944c68a2
Clean up aborted createWants stream
Otherwise, a createWants stream only gets cleaned up in the sink for the peer's createWants stream. But for a local RPC connection, we do not call createWants on the peer, so if the remote calls createWants, we have to clean it up after it is aborted. Here we do that it in the appropriate place.cel committed on 7/17/2017, 6:45:20 PM
Parent: c0e9a969c5c0484a867b4ca5508beaeff462f603
Files changed
inject.js | changed |
inject.js | |||
---|---|---|---|
@@ -30,8 +30,17 @@ | |||
30 | 30 … | for(var k in obj) c++ | |
31 | 31 … | return c | |
32 | 32 … | } | |
33 | 33 … | ||
34 … | +function onAbort(abortCb) { | ||
35 … | + return function (read) { | ||
36 … | + return function (abort, cb) { | ||
37 … | + if (abort) abortCb(abort, cb) | ||
38 … | + else read(null, cb) | ||
39 … | + } | ||
40 … | + } | ||
41 … | +} | ||
42 … | + | ||
34 | 43 … | module.exports = function inject (blobs, set, name, opts) { | |
35 | 44 … | opts = opts || {} | |
36 | 45 … | //sympathy controls whether you'll replicate | |
37 | 46 … | var sympathy = opts.sympathy == null ? 3 : opts.sympathy | 0 | |
@@ -198,12 +207,13 @@ | |||
198 | 207 … | //merge in ids we are pushing. | |
199 | 208 … | var w = clone(want) | |
200 | 209 … | for(var k in push) w[k] = -1 | |
201 | 210 … | streams[id].push(w) | |
202 | - | ||
203 | - return streams[id] | ||
204 | 211 … | } | |
205 | - return streams[id] | ||
212 … | + return pull(streams[id], onAbort(function (err, cb) { | ||
213 … | + streams[id] = false | ||
214 … | + cb(err) | ||
215 … | + })) | ||
206 | 216 … | } | |
207 | 217 … | ||
208 | 218 … | function wantSink (peer) { | |
209 | 219 … | createWantStream(peer.id) //set streams[peer.id] |
Built with git-ssb-web