Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Exits after 5 seconds w/o DEBUG, or gets stuck in infinite loop when running with DEBUG on #14

Open
da2x opened this issue May 5, 2019 · 3 comments

Comments

@da2x
Copy link
Contributor

da2x commented May 5, 2019

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 98522b7 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.

@da2x da2x changed the title Exits after 5 seconds or infinite loop with DEBUG=dat* dat-push Exits after 5 seconds, or gets stuck in infinite loop when running with DEBUG on May 5, 2019
@da2x da2x changed the title Exits after 5 seconds, or gets stuck in infinite loop when running with DEBUG on Exits after 5 seconds w/o DEBUG, or gets stuck in infinite loop when running with DEBUG on May 5, 2019
@da2x
Copy link
Contributor Author

da2x commented May 5, 2019

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

@da2x
Copy link
Contributor Author

da2x commented May 5, 2019

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.

stream.on('want', () => {

@ghost
Copy link

ghost commented Jun 21, 2019

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()
  }
})

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant