Commit 920e03133078d73d757126abd401f7d24180bfbc
Merge remote-tracking branch 'origin/stream-errors'
Dominic Tarr committed on 3/16/2017, 1:04:46 AMParent: 0fb85853eb9925412aa32e398713b8974aebb05a
Parent: 78f95a6d1fe17f7747c2076c9ca3c86762b5e7f5
Files changed
plugins/gossip/index.js | changed |
plugins/replicate.js | changed |
plugins/gossip/index.js | ||
---|---|---|
@@ -111,9 +111,9 @@ | ||
111 | 111 … | |
112 | 112 … | peer.state = 'disconnecting' |
113 | 113 … | peer.stateChange = Date.now() |
114 | 114 … | if(!peer || !peer.disconnect) cb && cb() |
115 | - else peer.disconnect(null, function (err) { | |
115 … | + else peer.disconnect(true, function (err) { | |
116 | 116 … | peer.stateChange = Date.now() |
117 | 117 … | }) |
118 | 118 … | |
119 | 119 … | }, 'string|object'), |
@@ -181,9 +181,18 @@ | ||
181 | 181 … | server.on('rpc:connect', function (rpc, isClient) { |
182 | 182 … | var peer = getPeer(rpc.id) |
183 | 183 … | //don't track clients that connect, but arn't considered peers. |
184 | 184 … | //maybe we should though? |
185 | - if(!peer) return | |
185 … | + if(!peer) { | |
186 … | + if(rpc.id !== server.id) { | |
187 … | + console.log('Connected', rpc.id) | |
188 … | + rpc.on('closed', function () { | |
189 … | + console.log('Disconnected', rpc.id) | |
190 … | + }) | |
191 … | + } | |
192 … | + return | |
193 … | + } | |
194 … | + | |
186 | 195 … | console.log('Connected', stringify(peer)) |
187 | 196 … | //means that we have created this connection, not received it. |
188 | 197 … | peer.client = !!isClient |
189 | 198 … | peer.state = 'connected' |
plugins/replicate.js | ||
---|---|---|
@@ -17,8 +17,21 @@ | ||
17 | 17 … | } |
18 | 18 … | |
19 | 19 … | function last (a) { return a[a.length - 1] } |
20 | 20 … | |
21 … | +// if one of these shows up in a replication stream, the stream is dead | |
22 … | +var streamErrors = { | |
23 … | + 'unexpected end of parent stream': true, // stream closed okay | |
24 … | + 'unexpected hangup': true, // stream closed probably okay | |
25 … | + 'read EHOSTUNREACH': true, | |
26 … | + 'read ECONNRESET': true, | |
27 … | + 'read ENETDOWN': true, | |
28 … | + 'read ETIMEDOUT': true, | |
29 … | + 'write ECONNRESET': true, | |
30 … | + 'write EPIPE': true, | |
31 … | + 'stream is closed': true, // rpc method called after stream ended | |
32 … | +} | |
33 … | + | |
21 | 34 … | module.exports = { |
22 | 35 … | name: 'replicate', |
23 | 36 … | version: '2.0.0', |
24 | 37 … | manifest: mdm.manifest(apidoc), |
@@ -183,8 +196,9 @@ | ||
183 | 196 … | rpc.on('closed', function () { |
184 | 197 … | sbot.emit('replicate:finish', to_send) |
185 | 198 … | }) |
186 | 199 … | var SYNC = false |
200 … | + var errorsSeen = {} | |
187 | 201 … | pull( |
188 | 202 … | upto({live: opts.live}), |
189 | 203 … | drain = pull.drain(function (upto) { |
190 | 204 … | if(upto.sync) return |
@@ -197,18 +211,35 @@ | ||
197 | 211 … | live: true, |
198 | 212 … | keys: false |
199 | 213 … | }), |
200 | 214 … | sbot.createWriteStream(function (err) { |
201 | - if(err) console.error(err.stack) | |
215 … | + if(err && !(err.message in errorsSeen)) { | |
216 … | + errorsSeen[err.message] = true | |
217 … | + if(err.message in streamErrors) { | |
218 … | + drain.abort() | |
219 … | + if(err.message === 'unexpected end of parent stream') { | |
220 … | + if (err instanceof Error) { | |
221 … | + // stream closed okay locally | |
222 … | + } else { | |
223 … | + // pre-emptively destroy the stream, assuming the other | |
224 … | + // end is packet-stream 2.0.0 sending end messages. | |
225 … | + rpc.close(err) | |
226 … | + } | |
227 … | + } | |
228 … | + } else { | |
229 … | + console.error('Error replicating with ' + rpc.id + ':\n ', | |
230 … | + err.stack) | |
231 … | + } | |
232 … | + } | |
202 | 233 … | |
203 | 234 … | feeds-- |
204 | 235 … | debounce.set() |
205 | 236 … | }) |
206 | 237 … | ) |
207 | 238 … | |
208 | 239 … | }, function (err) { |
209 | - if(err) | |
210 | - sbot.emit('log:error', ['replication', rep.id, 'error', err]) | |
240 … | + if(err && err !== true) | |
241 … | + sbot.emit('log:error', ['replication', rpc.id, 'error', err]) | |
211 | 242 … | }) |
212 | 243 … | ) |
213 | 244 … | }) |
214 | 245 … |
Built with git-ssb-web