RangerMauve / hyper-sdk

Make your own hyper apps!
https://www.youtube.com/watch?v=HyHk4aImd_I&list=PL7sG5SCUNyeYx8wnfMOUpsh7rM_g0w_cu&index=20
MIT License
290 stars 46 forks source link

'Error: Could not bind' #8

Closed DeltaF1 closed 5 years ago

DeltaF1 commented 5 years ago

Expected Behaviour:

Using the dat-sdk in two different instances of node should allow for cross-process swarming

Actual behaviour:

Requiring the dat-sdk while it is open in another node instance produces a traceback, and replication does not occur between processes

Environment:

Ubuntu on Windows Subsystem for Linux, node v10.16.0

Traceback:

> const {Hypercore} = require('dat-sdk')();
undefined
> Thrown:
{ Error: Could not bind
    at UTP.bind (/mnt/c/Users/Delta/Documents/hyperchat/node_modules/discovery-swarm/node_modules/utp-native/index.js:178:18)
    at UTP.listen (/mnt/c/Users/Delta/Documents/hyperchat/node_modules/discovery-swarm/node_modules/utp-native/index.js:190:32)
    at Server.ontcplisten (/mnt/c/Users/Delta/Documents/hyperchat/node_modules/discovery-swarm/index.js:510:15)
    at Server.emit (events.js:198:13)
    at Server.EventEmitter.emit (domain.js:466:23)
    at emitListeningNT (net.js:1313:10)
    at process._tickCallback (internal/process/next_tick.js:63:19)
  domainEmitter:
   Hyperdiscovery {
     domain:
      Domain {
        domain: null,
        _events: [Object],
        _eventsCount: 3,
        _maxListeners: undefined,
        members: [],
        [Symbol(kWeak)]: WeakReference {} },
     _events: [Object: null prototype] {},
     _eventsCount: 0,
     _maxListeners: undefined,
     _opts: { extensions: [] },
     id:
      <Buffer 9e f9 c7 ea 7f a1 1a ff d1 7c 0e c3 45 95 06 44 15 e5 d0 e8 8c f8 32 8a bf 56 e4 38 d6 e3 98 8a>,
     _port: 3282,
     _portAlts: [ 3000, 3002, 3004, 2001, 2003, 2005 ],
     _swarm:
      Swarm {
        domain: [Domain],
        _events: [Object],
        _eventsCount: 13,
        _maxListeners: undefined,
        maxConnections: 0,
        totalConnections: 0,
        connections: [],
        id:
         <Buffer 9e f9 c7 ea 7f a1 1a ff d1 7c 0e c3 45 95 06 44 15 e5 d0 e8 8c f8 32 8a bf 56 e4 38 d6 e3 98 8a>,
        destroyed: false,
        _stream: [Function: bound _createReplicationStream],
        _options: [Object],
        _whitelist: [],
        _discovery: null,
        _tcp: [Server],
        _utp: [UTP],
        _tcpConnections: [EventEmitter],
        _adding: [],
        _listening: true,
        _peersIds: {},
        _peersSeen: {},
        _peersQueued: [] },
     _replicatingFeeds: Map {} },
  domain:
   Domain {
     domain: null,
     _events:
      [Object: null prototype] {
        removeListener: [Function: updateExceptionCapture],
        newListener: [Function: updateExceptionCapture],
        error: [Function: debugDomainError] },
     _eventsCount: 3,
     _maxListeners: undefined,
     members: [],
     [Symbol(kWeak)]: WeakReference {} },
  domainThrown: false }
DeltaF1 commented 5 years ago

It looks like the problem is in hyperdiscovery.

https://github.com/datproject/hyperdiscovery/blob/b541263eb4ca89f442faa054ae89ac0b12f9133e/index.js#L40

It cycles through a list of default ports, but that list is the same for two different processes, so there will be a port conflict.

RangerMauve commented 5 years ago

Weird. If it fails one port, shouldn't it go to the next? 🤔

This might change once we migrate to hyperswarm within hyperdiscovery.

DeltaF1 commented 5 years ago

You're right it looks like it does try to cycle if the port is in use, so my guess might be off-base. The traceback leads to something to do with DNS in utp-native.

RangerMauve commented 5 years ago

Weeeeird. What OS and node version is this? I think it'll be safe to put off until we get hyperswarm integrated

DeltaF1 commented 5 years ago

Ubuntu on Windows Subsystem for Linux, node v10.16.0

okdistribute commented 5 years ago

It could be that up-native failed in your machine. Can you try node 8? And in the first few lines of discovery-swarm there is a try catch around the requiring of up-native and it doesn't print anything.. try printing there.

RangerMauve commented 5 years ago

Gonna close this for now since it's not reproducing.