Skip to content

Commit

Permalink
connectd: also fail without a scary backtrace when listen fails.
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
rustyrussell committed Mar 5, 2022
1 parent 885a6f5 commit b5a1715
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
16 changes: 9 additions & 7 deletions connectd/connectd.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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,
Expand All @@ -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:
Expand Down
1 change: 1 addition & 0 deletions connectd/connectd_wire.csv
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 14 additions & 2 deletions lightningd/connect_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit b5a1715

Please sign in to comment.