Description
Issue and Steps to Reproduce
- Compiled commit hash
d9b2482415a888d90e8d2a0f486bf96788e84b6f
(master) for MacOS - Start lightningd with
./lightningd/lightningd
- In separate terminal, attempt to send rpc request over the domain socket
~/.lightning/bitcoin/lightning-rpc
in one of 5 ways
Situation 1 (Unevaluated newline literals appended to json rpc message)
echo '{ "jsonrpc": "2.0", "method": "getinfo", "params": [], "id": 0 }\n\n' | nc -v -U ~/.lightning/bitcoin/lightning-rpc
- This yields two json rpc responses to the single request:
{"jsonrpc":"2.0","id":null,"error":{"code":-32600,"message":"Invalid token in json input"} }
{"jsonrpc":"2.0","id":0,"result":{"id":"039410872e426eba0284e7b90b997701e767a0b2f8da9692efd874ebaad4b0007d","alias":"PEEVEDSPAWN","color":"039410","num_peers":0,"num_pending_channels":0,"num_active_channels":0,"num_inactive_channels":0,"address":[],"binding":[{"type":"ipv6","address":"::","port":9735}],"version":"v0.8.1-50-gd9b2482","blockheight":344820,"network":"bitcoin","msatoshi_fees_collected":0,"fees_collected_msat":"0msat","lightning-dir":"/Users/keagan/.lightning/bitcoin","warning_bitcoind_sync":"Bitcoind is not up-to-date with network."} }
- It also yields in the lightningd stdout log:
2020-03-04T21:42:49.021Z UNUSUAL jsonrpc#29: Invalid token in json input: '\n\n?'
Situation 2 (Evaluated newlines appended to json rpc message)
echo -e '{ "jsonrpc": "2.0", "method": "getinfo", "params": [], "id": 0 }\n\n' | nc -v -U ~/.lightning/bitcoin/lightning-rpc
- This yields a segmentation fault
Situation 3 (Unevaluated newline literals appended to json rpc message, No echo newline)
echo -n '{ "jsonrpc": "2.0", "method": "getinfo", "params": [], "id": 0 }\n\n' | nc -v -U ~/.lightning/bitcoin/lightning-rpc
- This yields identical behavior to Situation 1
Situation 4 (Evaluated newlines appended to json rpc message, No echo newline)
echo -ne '{ "jsonrpc": "2.0", "method": "getinfo", "params": [], "id": 0 }\n\n' | nc -v -U ~/.lightning/bitcoin/lightning-rpc
- This yields a segmentation fault
Situation 5 (No newlines at the end of json rpc message, No echo newline)
echo -n '{ "jsonrpc": "2.0", "method": "getinfo", "params": [], "id": 0 }' | nc -v -U ~/.lightning/bitcoin/lightning-rpc
- This yields segmentation fault
getinfo
output
N/A, bug report is related to getting "getinfo"
Commentary
The closest I was able to get to behavior that was sane is with unevaluated newlines at the end of the message. This presumably pleases whatever system is reading messages off the socket, but is not pleasing the json parser, yet it still responds in a partially reasonable way: it gives me the response I was looking for, albeit with an erroneous extra complaint about the existence of newlines. The newline inserted by the echo
command itself does not seem to make a difference in the behavior here. In every case, I would expect that misuse of the API would result in a json rpc error as opposed to segfault and termination of lightningd. Similarly, getting two responses for a single request seems like unexpected behavior as well.