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

socket is closed #64

Open
fanatid opened this issue Apr 16, 2015 · 2 comments
Open

socket is closed #64

fanatid opened this issue Apr 16, 2015 · 2 comments

Comments

@fanatid
Copy link
Contributor

fanatid commented Apr 16, 2015

Check connection status before write? https://github.com/bitpay/bitcore-p2p/blob/master/lib/peer.js#L194

var bitcore = require('bitcore')
var Peer = require('bitcore-p2p').Peer
var peer = new Peer({host: 'localhost', port: 18333, network: bitcore.Networks.testnet})
peer.on('connect', function () { peer.disconnect() })
peer.connect()

Result:

events.js:72
        throw er; // Unhandled 'error' event
              ^
Error: This socket is closed.
    at Socket._write (net.js:638:19)
    at doWrite (_stream_writable.js:226:10)
    at writeOrBuffer (_stream_writable.js:216:5)
    at Socket.Writable.write (_stream_writable.js:183:11)
    at Socket.write (net.js:616:40)
    at Peer.sendMessage (/home/kirill/.../node_modules/bitcore-p2p/lib/peer.js:194:15)
    at Peer._sendVersion (/home/kirill/.../node_modules/bitcore-p2p/lib/peer.js:204:8)
    at Socket.<anonymous> (/home/kirill/.../node_modules/bitcore-p2p/lib/peer.js:146:10)
    at Socket.emit (events.js:117:20)
    at Object.afterConnect [as oncomplete] (net.js:887:10)
@braydonf
Copy link
Contributor

If there was a check, it would still throw an error though. It could be better to check the status before sending a message and then if it's not ready, use a different peer. Alternatively peers in a pool are removed when they are disconnected, and pool.sendMessage will send to all the connected peers.

@fanatid
Copy link
Contributor Author

fanatid commented Apr 16, 2015

I think custom error is better than This socket is closed because node.js process will be alive.
Thanks for hint about connected peers in Pool, I'll see.

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

2 participants