common/msg_queue: send backtrace on oversize queues.

Scary looking, but great for debugging!

Signed-off-by: Rusty Russell <rusty@rustcorp.com.au>
This commit is contained in:
Rusty Russell 2024-10-28 20:25:50 +10:30
parent 1051e97d69
commit 1e4adbff17
14 changed files with 58 additions and 2 deletions

View File

@ -13,6 +13,7 @@ static bool print_superverbose;
#include <ccan/err/err.h>
#include <ccan/str/hex/hex.h>
#include <common/channel_id.h>
#include <common/daemon.h>
#include <common/key_derive.h>
#include <common/setup.h>
#include <common/status.h>
@ -34,6 +35,9 @@ void fromwire_node_id(const u8 **cursor UNNEEDED, size_t *max UNNEEDED, struct n
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for status_fmt */
void status_fmt(enum log_level level UNNEEDED,
const struct node_id *peer UNNEEDED,

View File

@ -9,6 +9,7 @@
#include "../full_channel.c"
#include "../commit_tx.c"
#include <ccan/err/err.h>
#include <common/daemon.h>
#include <common/setup.h>
/* AUTOGENERATED MOCKS START */
@ -27,6 +28,9 @@ void memleak_scan_htable(struct htable *memtable UNNEEDED, const struct htable *
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for status_failed */
void status_failed(enum status_failreason code UNNEEDED,
const char *fmt UNNEEDED, ...)

View File

@ -4,6 +4,7 @@
#include <common/bigsize.h>
#include <common/channel_id.h>
#include <common/configvar.h>
#include <common/daemon.h>
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/setup.h>
@ -92,6 +93,9 @@ bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED,
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }

View File

@ -4,6 +4,7 @@
#include <common/bigsize.h>
#include <common/channel_id.h>
#include <common/configvar.h>
#include <common/daemon.h>
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/setup.h>
@ -92,6 +93,9 @@ bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED,
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }

View File

@ -4,6 +4,7 @@
#include <common/bigsize.h>
#include <common/channel_id.h>
#include <common/configvar.h>
#include <common/daemon.h>
#include <common/json_stream.h>
#include <common/node_id.h>
#include <common/setup.h>
@ -95,6 +96,9 @@ bool log_level_parse(const char *levelstr UNNEEDED, size_t len UNNEEDED,
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_amount_msat */
void towire_amount_msat(u8 **pptr UNNEEDED, const struct amount_msat msat UNNEEDED)
{ fprintf(stderr, "towire_amount_msat called!\n"); abort(); }

View File

@ -2,10 +2,13 @@
#include <assert.h>
#include <ccan/cast/cast.h>
#include <ccan/membuf/membuf.h>
#include <common/daemon.h>
#include <common/msg_queue.h>
#include <common/utils.h>
#include <wire/wire.h>
static bool warned_once;
struct msg_queue {
bool fd_passing;
MEMBUF(const u8 *) mb;
@ -60,6 +63,12 @@ static void do_enqueue(struct msg_queue *q, const u8 *add TAKES)
*msg = tal_dup_talarr(q, u8, add);
if (!warned_once && msg_queue_length(q) > 100000) {
/* Can cause re-entry, so set flag first! */
warned_once = true;
send_backtrace("excessive queue length");
}
/* In case someone is waiting */
io_wake(q);
}

View File

@ -2,6 +2,7 @@
#include "../gossip_generation.c"
#include <common/blinding.h>
#include <common/channel_type.h>
#include <common/daemon.h>
#include <common/ecdh.h>
#include <common/json_stream.h>
#include <common/onionreply.h>
@ -35,6 +36,9 @@ int node_id_cmp(const struct node_id *a UNNEEDED, const struct node_id *b UNNEED
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }

View File

@ -230,6 +230,9 @@ struct runes *runes_early_init(struct lightningd *ld UNNEEDED)
/* Generated stub for runes_finish_init */
void runes_finish_init(struct runes *runes UNNEEDED)
{ fprintf(stderr, "runes_finish_init called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for setup_color_and_alias */
void setup_color_and_alias(struct lightningd *ld UNNEEDED)
{ fprintf(stderr, "setup_color_and_alias called!\n"); abort(); }

View File

@ -3,6 +3,7 @@
#include "../peer_control.c"
#include "../routehint.c"
#include <ccan/alignof/alignof.h>
#include <common/daemon.h>
#include <common/errcode.h>
#include <common/setup.h>
#include <stdio.h>
@ -920,6 +921,9 @@ void report_subd_memleak(struct leak_detect *leak_detect UNNEEDED, struct subd *
void resolve_close_command(struct lightningd *ld UNNEEDED, struct channel *channel UNNEEDED,
bool cooperative UNNEEDED, const struct bitcoin_tx *close_tx UNNEEDED)
{ fprintf(stderr, "resolve_close_command called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for shachain_get_secret */
bool shachain_get_secret(const struct shachain *shachain UNNEEDED,
u64 commit_num UNNEEDED,

View File

@ -3,6 +3,7 @@
#include "../../common/json_stream.c"
#include "../jsonrpc.c"
#include "../feerate.c"
#include <common/daemon.h>
#include <common/setup.h>
#include <stdio.h>
@ -160,6 +161,9 @@ bool plugin_hook_call_(struct lightningd *ld UNNEEDED,
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }

View File

@ -1,5 +1,6 @@
#include "config.h"
#include "../log.c"
#include <common/daemon.h>
#include <common/setup.h>
/* AUTOGENERATED MOCKS START */
@ -99,6 +100,9 @@ bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED,
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }

View File

@ -1,4 +1,5 @@
#include "config.h"
#include <common/daemon.h>
#include <common/node_id.c>
#include <common/setup.h>
#include <common/status_levels.c>
@ -91,6 +92,9 @@ void notify_warning(struct lightningd *ld UNNEEDED, struct log_entry *l UNNEEDED
bool param(struct command *cmd UNNEEDED, const char *buffer UNNEEDED,
const jsmntok_t params[] UNNEEDED, ...)
{ fprintf(stderr, "param called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for towire_bigsize */
void towire_bigsize(u8 **pptr UNNEEDED, const bigsize_t val UNNEEDED)
{ fprintf(stderr, "towire_bigsize called!\n"); abort(); }

View File

@ -37,6 +37,7 @@ static int test_fcntl(int fd, int cmd, ... /* arg */ )
}
#include "../subd.c"
#include <common/daemon.h>
#include <common/json_stream.h>
#include <common/setup.h>
@ -104,6 +105,9 @@ struct peer_fd *new_peer_fd_arr(const tal_t *ctx UNNEEDED, const int *fd UNNEEDE
/* Generated stub for pubkey_from_node_id */
bool pubkey_from_node_id(struct pubkey *key UNNEEDED, const struct node_id *id UNNEEDED)
{ fprintf(stderr, "pubkey_from_node_id called!\n"); abort(); }
/* Generated stub for send_backtrace */
void send_backtrace(const char *why UNNEEDED)
{ fprintf(stderr, "send_backtrace called!\n"); abort(); }
/* Generated stub for subdaemon_path */
const char *subdaemon_path(const tal_t *ctx UNNEEDED, const struct lightningd *ld UNNEEDED, const char *name UNNEEDED)
{ fprintf(stderr, "subdaemon_path called!\n"); abort(); }

View File

@ -737,7 +737,7 @@ enum watch_result onchaind_funding_spent(struct channel *channel UNNEEDED,
/* Generated stub for onion_decode */
struct onion_payload *onion_decode(const tal_t *ctx UNNEEDED,
const struct route_step *rs UNNEEDED,
const struct pubkey *blinding UNNEEDED,
const struct pubkey *path_key UNNEEDED,
const u64 *accepted_extra_tlvs UNNEEDED,
struct amount_msat amount_in UNNEEDED,
u32 cltv_expiry UNNEEDED,
@ -1036,7 +1036,7 @@ u8 *towire_channeld_got_commitsig_reply(const tal_t *ctx UNNEEDED)
u8 *towire_channeld_got_revoke_reply(const tal_t *ctx UNNEEDED)
{ fprintf(stderr, "towire_channeld_got_revoke_reply called!\n"); abort(); }
/* Generated stub for towire_channeld_offer_htlc */
u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amount_msat UNNEEDED, u32 cltv_expiry UNNEEDED, const struct sha256 *payment_hash UNNEEDED, const u8 onion_routing_packet[1366] UNNEEDED, const struct pubkey *blinding UNNEEDED)
u8 *towire_channeld_offer_htlc(const tal_t *ctx UNNEEDED, struct amount_msat amount_msat UNNEEDED, u32 cltv_expiry UNNEEDED, const struct sha256 *payment_hash UNNEEDED, const u8 onion_routing_packet[1366] UNNEEDED, const struct pubkey *path_key UNNEEDED)
{ fprintf(stderr, "towire_channeld_offer_htlc called!\n"); abort(); }
/* Generated stub for towire_channeld_sending_commitsig_reply */
u8 *towire_channeld_sending_commitsig_reply(const tal_t *ctx UNNEEDED)