Skip to content

Commit f658dd0

Browse files
committed
pytest: test connection timeout.
Signed-off-by: Rusty Russell <[email protected]>
1 parent 7f2b332 commit f658dd0

File tree

2 files changed

+25
-4
lines changed

2 files changed

+25
-4
lines changed

connectd/connectd.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -518,7 +518,9 @@ static struct io_plan *handshake_in_success(struct io_conn *conn,
518518
/*~ If the timer goes off, we simply free everything, which hangs up. */
519519
static void conn_timeout(struct io_conn *conn)
520520
{
521-
tal_free(conn);
521+
status_debug("conn timed out");
522+
errno = ETIMEDOUT;
523+
io_close(conn);
522524
}
523525

524526
/*~ When we get a connection in we set up its network address then call
@@ -1672,9 +1674,11 @@ int main(int argc, char *argv[])
16721674
* status_failed on error. */
16731675
ecdh_hsmd_setup(HSM_FD, status_failed);
16741676

1675-
/* Should never exit. */
1676-
io_loop(NULL, NULL);
1677-
abort();
1677+
for (;;) {
1678+
struct timer *expired;
1679+
io_loop(&daemon->timers, &expired);
1680+
timer_expired(daemon, expired);
1681+
}
16781682
}
16791683

16801684
/*~ Getting bored? This was a pretty simple daemon!

tests/test_connection.py

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2634,3 +2634,20 @@ def test_nonstatic_channel(node_factory, bitcoind):
26342634

26352635
l1.pay(l2, 1000)
26362636
l1.rpc.close(l2.info['id'])
2637+
2638+
2639+
@unittest.skipIf(not DEVELOPER, "needs --dev-timeout-secs")
2640+
def test_connection_timeout(node_factory):
2641+
# l1 hears nothing back after sending INIT, should time out.
2642+
l1, l2 = node_factory.get_nodes(2,
2643+
opts=[{'dev-timeout-secs': 1,
2644+
'disconnect': ['0WIRE_INIT', '0WIRE_INIT']},
2645+
{}])
2646+
2647+
with pytest.raises(RpcError, match='timed out'):
2648+
l1.rpc.connect(l2.info['id'], 'localhost', port=l2.port)
2649+
l1.daemon.wait_for_log('conn timed out')
2650+
2651+
with pytest.raises(RpcError, match='reset by peer'):
2652+
l2.rpc.connect(l1.info['id'], 'localhost', port=l1.port)
2653+
l1.daemon.wait_for_log('conn timed out')

0 commit comments

Comments
 (0)