I sent RPC command to the P2P port of XUD
./xucli -p 8885 getinfo
XUD crashed with:
8/8/2018, 9:41:55 AM [P2P] debug: Received data (127.0.0.1:65512):
/Users/admin/github/xud/dist/bootstrap.js:13
throw err;
identity,gzip: SyntaxError: Unexpected token in JSON at position 0
^
8/8/2018, 9:41:55 AM [P2P] Error: Peer was destroyed
warn at Peer.close (/Users/admin/github/xud/dist/p2p/Peer.js:92:30)
: Unparsable peer message: : SyntaxError: Unexpected token in JSON at position 0
at Socket.socket.once (/Users/admin/github/xud/dist/p2p/Peer.js:284:22)
8/8/2018, 9:41:55 AM [P2P] at Object.onceWrapper (events.js:273:13)
info at Socket.emit (events.js:182:13)
: Socket closed (127.0.0.1:65512)
at TCP._handle.close (net.js:599:12)
8/8/2018, 9:41:55 AM [P2P] warn: disconnected peer (127.0.0.1:65512) hostId is missing
Error: Peer was destroyed
at Peer.close (/Users/admin/github/xud/dist/p2p/Peer.js:92:30)
at Socket.socket.once (/Users/admin/github/xud/dist/p2p/Peer.js:284:22)
at Object.onceWrapper (events.js:273:13)
at Socket.emit (events.js:182:13)
at TCP._handle.close (net.js:599:12)
Process finished with exit code 1
Needs a generic way to catch all unexpected messages to all grpc/cli/p2p ports
Would like to take over on this, have you done anything related with this @sangaman or do you have anything in mind ?
if it's still an issue though :)
I have not worked on this yet, so please do take a look as this is definitely something that needs to fixed. I'm not sure if it's still an issue or if it was solved through other changes, but I suspect it would still crash. It's easy to test tho as all you need to do is send rpc calls to the p2p port using the command from the issue. We would just need a way to gracefully handle invalid messages sent to the p2p layer. I'd also put in a TODO note somewhere in your handling logic that we should ban IP addresses that repeatedly send us invalid data.
It's currently not throwing errors as described;
From daemon;
2018-9-15 15:47:02 [P2P] warn: error while opening connection to peer (127.0.0.1:48276): Peer was destroyed
From client;
sercan@sercan:~/WebstormProjects/xud/bin$ ./xucli -p 8885 getinfo
Error: 2 UNKNOWN: Stream removed
I don't know if this's desired behavior ?
That seems good enough to me, thanks!
So this one magically fixed itself? @sangaman
I'd guess it was fixed with the parser/packet structure changes in #330, which were merged after this issue was opened.
Most helpful comment
I'd guess it was fixed with the parser/packet structure changes in #330, which were merged after this issue was opened.