diff --git a/connectd/connectd.c b/connectd/connectd.c index 2c1697101..f75fbaf1f 100644 --- a/connectd/connectd.c +++ b/connectd/connectd.c @@ -20,6 +20,7 @@ #include #include #include +#include #include #include #include @@ -566,11 +567,18 @@ static void PRINTF_FMT(5,6) static void destroy_io_conn(struct io_conn *conn, struct connecting *connect) { /*~ tal_append_fmt appends to a tal string. It's terribly convenient */ + const char *errstr = strerror(errno); + /* errno 0 means they hung up on us. */ + if (errno == 0) { + errstr = "peer closed connection"; + if (streq(connect->connstate, "Cryptographic handshake")) + errstr = "peer closed connection (wrong key?)"; + } tal_append_fmt(&connect->errors, "%s: %s: %s. ", type_to_string(tmpctx, struct wireaddr_internal, &connect->addrs[connect->addrnum]), - connect->connstate, strerror(errno)); + connect->connstate, errstr); connect->addrnum++; try_connect_one_addr(connect); } diff --git a/tests/test_connection.py b/tests/test_connection.py index c682dfdca..3bd7781e3 100644 --- a/tests/test_connection.py +++ b/tests/test_connection.py @@ -41,7 +41,7 @@ def test_connect(node_factory): l1.rpc.connect('032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', 1) # Should get reasonable error if wrong key for peer. - with pytest.raises(RpcError, match=r'Cryptographic handshake: '): + with pytest.raises(RpcError, match=r'Cryptographic handshake: peer closed connection \(wrong key\?\)'): l1.rpc.connect('032cf15d1ad9c4a08d26eab1918f732d8ef8fdc6abb9640bf3db174372c491304e', 'localhost', l2.port)