connectd: also fail without a scary backtrace when listen fails.

For example, if you do:

```
./lightningd/lightningd --network=regtest --experimental-websocket-port=19846
```

Then you're trying to reuse the normal port as the websocket port, but this
only fails at *listen* time, when we activate connectd.  Catch this too.

Fixes incorrect fatal() message, too.

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2022-03-04 16:40:57 +10:30
parent 885a6f50ae
commit b5a1715c2b
3 changed files with 24 additions and 9 deletions

View File

@ -1657,6 +1657,7 @@ static struct io_plan *(*get_in_cb(enum is_websocket is_websocket))(struct io_co
static void connect_activate(struct daemon *daemon, const u8 *msg)
{
bool do_listen;
char *errmsg = NULL;
if (!fromwire_connectd_activate(msg, &do_listen))
master_badmsg(WIRE_CONNECTD_ACTIVATE, msg);
@ -1667,12 +1668,13 @@ static void connect_activate(struct daemon *daemon, const u8 *msg)
if (listen(daemon->listen_fds[i]->fd, 64) != 0) {
if (daemon->listen_fds[i]->mayfail)
continue;
status_failed(STATUS_FAIL_INTERNAL_ERROR,
"Failed to listen on socket %s: %s",
type_to_string(tmpctx,
struct wireaddr_internal,
&daemon->listen_fds[i]->wi),
strerror(errno));
errmsg = tal_fmt(tmpctx,
"Failed to listen on socket %s: %s",
type_to_string(tmpctx,
struct wireaddr_internal,
&daemon->listen_fds[i]->wi),
strerror(errno));
break;
}
notleak(io_new_listener(daemon,
daemon->listen_fds[i]->fd,
@ -1687,7 +1689,7 @@ static void connect_activate(struct daemon *daemon, const u8 *msg)
/* OK, we're ready! */
daemon_conn_send(daemon->master,
take(towire_connectd_activate_reply(NULL)));
take(towire_connectd_activate_reply(NULL, errmsg)));
}
/* BOLT #10:

View File

@ -40,6 +40,7 @@ msgdata,connectd_activate,listen,bool,
# Connectd->master, I am ready.
msgtype,connectd_activate_reply,2125
msgdata,connectd_activate_reply,failmsg,?wirestring,
# connectd->master: disconnect this peer please (due to reconnect).
msgtype,connectd_reconnected,2112

1 #include <bitcoin/block.h>
40 msgtype,connectd_reconnected,2112 # connectd->master: disconnect this peer please (due to reconnect).
41 msgdata,connectd_reconnected,id,node_id, msgtype,connectd_reconnected,2112
42 # Master -> connectd: connect to a peer. msgdata,connectd_reconnected,id,node_id,
43 # Master -> connectd: connect to a peer.
44 msgtype,connectd_connect_to_peer,2001
45 msgdata,connectd_connect_to_peer,id,node_id,
46 msgdata,connectd_connect_to_peer,seconds_waited,u32,

View File

@ -471,7 +471,7 @@ static void connect_init_done(struct subd *connectd,
&ld->binding,
&ld->announcable,
&errmsg))
fatal("Bad connectd_activate_reply: %s",
fatal("Bad connectd_init_reply: %s",
tal_hex(reply, reply));
/* connectd can fail in *informative* ways: don't use fatal() here and
@ -549,10 +549,22 @@ int connectd_init(struct lightningd *ld)
}
static void connect_activate_done(struct subd *connectd,
const u8 *reply UNUSED,
const u8 *reply,
const int *fds UNUSED,
void *unused UNUSED)
{
char *errmsg;
if (!fromwire_connectd_activate_reply(reply, reply, &errmsg))
fatal("Bad connectd_activate_reply: %s",
tal_hex(reply, reply));
/* connectd can fail in *informative* ways: don't use fatal() here and
* confuse things with a backtrace! */
if (errmsg) {
log_broken(connectd->log, "%s", errmsg);
exit(1);
}
/* Break out of loop, so we can begin */
io_break(connectd);
}