mappum / bitcoin-net

:globe_with_meridians: Bitcoin networking that works in Node and the browser
24 stars 22 forks source link

PeerGroup close callback is called before all sockets are closed #131

Open paulkernfeld opened 7 years ago

paulkernfeld commented 7 years ago

As far as I can tell, the close method of PeerGroup does successfully close it, but the callback is called before it's really closed. Specifically, it looks like TCP connections can still be opened after close is called. Maybe we could count the number of open TCP connections and only call the callback after count goes to zero?

  simple-block-stream closing... +31ms
  bitcoin-net:peergroup close called: peers.length = 0 +1ms
// At this point, PeerGroup calls the callback
  simple-block-stream closed +0ms
  simple-block-stream streaming from 278336 73a362d87ddf3cd111a53532dc711d2869054064fd38032a0000000000000000 +8ms
  simple-block-stream starting txs... +1ms
  bitcoin-net:peergroup _connectTCP: tcp://96.2.103.25:8333 +5ms
  bitcoin-net:peergroup _connectTCP: tcp://108.44.238.26:8333 +3ms
  bitcoin-net:peergroup _connectTCP: tcp://122.133.113.149:8333 +1ms
  bitcoin-net:peergroup _connectTCP: tcp://169.255.57.31:8333 +0ms
  bitcoin-net:peergroup _connectTCP: tcp://124.82.29.181:8333 +1ms
  bitcoin-net:peergroup _connectTCP: tcp://46.17.103.64:8333 +29ms
  bitcoin-net:peergroup _connectTCP: tcp://37.146.53.88:8333 +25ms
  bitcoin-net:peergroup _connectTCP: tcp://103.255.25.89:8333 +9ms
  bitcoin-net:peergroup discovery connection error: Connection timed out +8s