Skip to content

Commit f7b9edf

Browse files
fix(log): gate packet hexdumps off + grow the log-processing stack
The net image stack-overflowed the log thread at network-up: formatting a queued message on the deferred log-processing thread (or, in immediate mode, the emitting SMP/UDP transport thread) exceeded its ~1 KB stack and faulted the system, so the node joined WiFi, got an IP, then died before it was reachable. The deepest formatter is the full-packet hex dump (up to ~256 bytes) logged on every TX and RX. Turn it off by default (MESHTASTIC_PACKET_HEXDUMP default n, was on whenever the log level was DBG) and document the stack-overflow risk on the Kconfig and at both call sites. Also give the log-processing thread modest headroom (CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048, was the ~1 KB default). Verified on a Heltec V3: the net-ota image now boots, joins WiFi, and is reachable over SMP + telnet with no fault.
1 parent 4153341 commit f7b9edf

4 files changed

Lines changed: 23 additions & 2 deletions

File tree

samples/meshtastic/prj.conf

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,20 @@ CONFIG_LOG_DEFAULT_LEVEL=3
99
# messages (bumping a dropped counter) rather than blocking — bump back toward
1010
# 2048 if `log stats` shows drops that matter.
1111
CONFIG_LOG_BUFFER_SIZE=1024
12+
# The deferred log-processing thread formats each message on its own stack; the
13+
# Zephyr default (~1 KB) is too tight for meshtastic's larger messages and
14+
# overflowed the log thread at network-up on the V3. Give it modest headroom.
15+
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=2048
1216

1317
CONFIG_MAIN_STACK_SIZE=8192
1418

1519
CONFIG_MESHTASTIC=y
1620
CONFIG_MESHTASTIC_SETTINGS=y
1721
CONFIG_MESHTASTIC_LOG_LEVEL_DBG=y
18-
CONFIG_MESHTASTIC_PACKET_HEXDUMP=y
22+
# Packet hex dumps stay OFF (MESHTASTIC_PACKET_HEXDUMP): dumping a full ~256-byte
23+
# packet per TX/RX is the deepest formatter on the log path and can overflow the
24+
# log-thread stack. Enable it (and raise CONFIG_LOG_PROCESS_THREAD_STACK_SIZE)
25+
# only for wire-level debugging.
1926

2027
# for persistent settings
2128
CONFIG_NVS=y

src/Kconfig.core

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,12 +67,22 @@ config MESHTASTIC_OUTBOUND_STACK_SIZE
6767

6868
config MESHTASTIC_PACKET_HEXDUMP
6969
bool "Hex dump LoRa wire packets at DBG log level"
70-
default MESHTASTIC_LOG_LEVEL_DBG
70+
default n
7171
help
7272
When enabled and the meshtastic log level is DBG, log a hex dump of
7373
each Meshtastic wire packet (16-byte header plus encrypted payload)
7474
on transmit and receive.
7575

76+
WARNING: off by default because it is expensive on the log stack. It
77+
dumps up to the full packet (~256 bytes) on every TX and RX, and
78+
formatting a dump that large is deep on the stack of whichever thread
79+
runs the log backend — the log-processing thread in deferred mode, or the
80+
emitting thread (e.g. the SMP/UDP transport) in immediate mode. With a
81+
tight CONFIG_LOG_PROCESS_THREAD_STACK_SIZE this can overflow that thread's
82+
stack and fault the system (observed at network-up on the Heltec V3).
83+
Enable only for wire-level debugging, and raise
84+
CONFIG_LOG_PROCESS_THREAD_STACK_SIZE if you turn it on.
85+
7686
config MESHTASTIC_DEFAULT_HOP_LIMIT
7787
int "Default hop limit for outgoing packets"
7888
default 3

src/meshtastic_radio.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,8 @@ static void log_wire_tx(const uint8_t *pkt, uint32_t pkt_len)
154154
LOG_DBG("LoRa TX %08x->%08x id=%08x ch=0x%02x len=%u",
155155
(unsigned int)sys_le32_to_cpu(hdr->src), (unsigned int)sys_le32_to_cpu(hdr->dest),
156156
(unsigned int)sys_le32_to_cpu(hdr->id), hdr->channel, (unsigned int)pkt_len);
157+
/* Deep log-stack formatter (~256 B) — gated + off by default; see the
158+
* stack-overflow warning on CONFIG_MESHTASTIC_PACKET_HEXDUMP. */
157159
LOG_HEXDUMP_DBG(pkt, pkt_len, "LoRa TX");
158160
}
159161
#endif /* CONFIG_MESHTASTIC_PACKET_HEXDUMP */

src/meshtastic_router.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -210,6 +210,8 @@ static void log_wire_rx(const uint8_t *pkt, int len, int16_t rssi, int8_t snr)
210210
LOG_DBG("LoRa RX %08x->%08x id=%08x ch=0x%02x len=%d rssi=%d snr=%d",
211211
(unsigned int)sys_le32_to_cpu(hdr->src), (unsigned int)sys_le32_to_cpu(hdr->dest),
212212
(unsigned int)sys_le32_to_cpu(hdr->id), hdr->channel, len, (int)rssi, (int)snr);
213+
/* Deep log-stack formatter (~256 B) — gated + off by default; see the
214+
* stack-overflow warning on CONFIG_MESHTASTIC_PACKET_HEXDUMP. */
213215
LOG_HEXDUMP_DBG(pkt, len, "LoRa RX");
214216
}
215217
#endif /* CONFIG_MESHTASTIC_PACKET_HEXDUMP */

0 commit comments

Comments
 (0)