git ssb

4+

Dominic / scuttlebot



Commit 920e03133078d73d757126abd401f7d24180bfbc

Merge remote-tracking branch 'origin/stream-errors'

Dominic Tarr committed on 3/16/2017, 1:04:46 AM
Parent: 0fb85853eb9925412aa32e398713b8974aebb05a
Parent: 78f95a6d1fe17f7747c2076c9ca3c86762b5e7f5

Files changed

plugins/gossip/index.jschanged
plugins/replicate.jschanged
plugins/gossip/index.jsView
@@ -111,9 +111,9 @@
111111
112112 peer.state = 'disconnecting'
113113 peer.stateChange = Date.now()
114114 if(!peer || !peer.disconnect) cb && cb()
115- else peer.disconnect(null, function (err) {
115 + else peer.disconnect(true, function (err) {
116116 peer.stateChange = Date.now()
117117 })
118118
119119 }, 'string|object'),
@@ -181,9 +181,18 @@
181181 server.on('rpc:connect', function (rpc, isClient) {
182182 var peer = getPeer(rpc.id)
183183 //don't track clients that connect, but arn't considered peers.
184184 //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 +
186195 console.log('Connected', stringify(peer))
187196 //means that we have created this connection, not received it.
188197 peer.client = !!isClient
189198 peer.state = 'connected'
plugins/replicate.jsView
@@ -17,8 +17,21 @@
1717 }
1818
1919 function last (a) { return a[a.length - 1] }
2020
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 +
2134 module.exports = {
2235 name: 'replicate',
2336 version: '2.0.0',
2437 manifest: mdm.manifest(apidoc),
@@ -183,8 +196,9 @@
183196 rpc.on('closed', function () {
184197 sbot.emit('replicate:finish', to_send)
185198 })
186199 var SYNC = false
200 + var errorsSeen = {}
187201 pull(
188202 upto({live: opts.live}),
189203 drain = pull.drain(function (upto) {
190204 if(upto.sync) return
@@ -197,18 +211,35 @@
197211 live: true,
198212 keys: false
199213 }),
200214 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 + }
202233
203234 feeds--
204235 debounce.set()
205236 })
206237 )
207238
208239 }, 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])
211242 })
212243 )
213244 })
214245

Built with git-ssb-web