Exits after 5 seconds w/o DEBUG, or gets stuck in infinite loop when running with DEBUG on
dat-push exits five seconds after the remote client connects unless I run with DEUBG=dat*. Transfer seems to work for the first five seconds regardless of running with DEBUG or not. The timeout introduced in https://github.com/joehand/dat-push/commit/98522b7479f3225cd0960d9555748609992c3bf9 by @pfrazee doesn’t seem to work as expected.
When I do run with debug the receiving end gets stuck printing this line every one second forever:
dat-network Uploaded data: 29847974 +501ms
The remote receiving end with DEBUG will print this corresponding message every one second forever:
dat-network Downloaded data: 29847974 +500ms`
dat-push will print that it is uploading a few other packets and then print Finished replicating with 1.2.3.4 twice prior to both sides getting stuck in this loop. Without DEBUG dat-push exits and the remote end complains that there are no peers before also exiting.
dat-push seems to start replicating with two copies of the same peer and then thinks it has finished replicating witch each copy twice.
$ DEBUG=dat-push dat-push --dir public/ example.com
{ _: [ 'example.com' ], dir: 'public/' }
[ '/usr/bin/node',
'/usr/bin/dat-push',
'--dir',
'public/',
'example.com' ]
dat-push dir public/ +0ms
dat-push dns lookup example.com +0ms
dat-push resolved example.com to 1.2.3.4 +3ms
Importing newest files...
Joining network...
Searching for targets...
dat-push joined network +36ms
Replicating with 1.2.3.4
Replicating with 1.2.3.4
Finished replicating with 1.2.3.4
dat-push stream close +12s
dat-push peer count: { total: 0, complete: 0 } +0ms
dat-push done() -1 +1ms
dat-push no want-msg received in 5000ms, closing stream +10ms
Finished replicating with 1.2.3.4
dat-push stream close +0ms
dat-push peer count: { total: 0, complete: 0 } +0ms
dat-push done() -2 +0ms
Finished replicating with 1.2.3.4
dat-push stream close +2ms
dat-push peer count: { total: 0, complete: 0 } +0ms
dat-push done() -3 +0ms
dat-push no want-msg received in 5000ms, closing stream +591ms
Finished replicating with 1.2.3.4
dat-push stream close +1ms
dat-push peer count: { total: 0, complete: 0 } +0ms
dat-push done() -4 +0ms
How often is the "want" event expected to be emitted? I added logging here and disabled the timeout and can then transfer data for several minutes without receiving a single 'want' event to reset the timeout.
https://github.com/joehand/dat-push/blob/1346982514880b514a4aadf119471725053edc10/index.js#L84
I found the same thing looking at this module while digging into have/wants. Here is how I found to add have/want listeners to replication streams: https://gist.github.com/substack/c69c2013c0694176ce9f36b0fa848c12
So that part of dat-push/index.js should be something like:
stream.on('feed', (id) => {
var ch = stream._feed(id)
if (ch.id <= -1) return
if (!ch.peer) ch.peer = {}
var prev = ch.peer.onwant
ch.peer.onwant = function () {
if (typeof prev === 'function') prev.apply(this, arguments)
clearTimeout(to)
to = startTheClock()
}
})