Debug Console: the listener is checked and retried, and debug off <seconds> comes back by itself
CI / build (pull_request) Successful in 7m10s
Site / build (pull_request) Successful in 14s

The framework's server begin() fails without a word: the console's task now
asks whether it listens, says so, and tries again. `debug off <seconds>`
closes the console and reopens it after the pause, which is the only way to
test its closing and reopening from afar.

Checked on the device: 25 closings and reopenings, each back a second after
the pause. Free heap dips about 270 bytes for each connection the device
closes and is all back two minutes later (TCP keeps a closed connection that
long): not a leak.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
2026-10-06 23:50:41 +02:00
co-authored by Claude Opus 5.5
parent c68741cc46
commit 1874a1b586
7 changed files with 51 additions and 9 deletions
+16 -3
View File
@@ -130,12 +130,23 @@ void DebugConsole::taskEntry(void* self) { static_cast<DebugConsole*>(self)->lis
void DebugConsole::listen() {
{
NetworkServer server(kPort);
bool listening = false;
bool listening = false, complained = false;
while (wanted_) {
bool up = wifi_.state() == WifiController::State::Connected;
if (up && !listening) {
// begin() gives up without a word (no socket, the port taken): ask whether it
// listens, and try again rather than believe it.
server.begin();
listening = true;
listening = static_cast<bool>(server);
if (!listening) {
if (!complained) console.printf("debug: can't listen on port %u (errno %d), trying again\n", kPort, errno);
complained = true;
server.end(); // closes the socket a failed begin() leaves open
vTaskDelay(pdMS_TO_TICKS(2000));
} else if (complained) {
console.printf("debug: listening on port %u\n", kPort);
complained = false;
}
} else if (!up && listening) {
server.end();
listening = false;
@@ -152,7 +163,9 @@ void DebugConsole::listen() {
}
if (listening) server.end();
}
// Switched off: nothing is left behind (Q189). The commands a client queued die with it.
// Switched off: nothing is left behind (Q189). The commands a client queued die with it. (Free
// heap dips by about 270 bytes for each connection the device closed, for two minutes: TCP keeps
// them that long. Measured over 15 switches: all of it comes back.)
xSemaphoreTake(lock_, portMAX_DELAY);
commands_.clear();
xSemaphoreGive(lock_);