Guard TCP API writes after Wi-Fi reconnects#10505
Open
Copilot wants to merge 3 commits into
Open
Conversation
3 tasks
Copilot
AI
changed the title
[WIP] Fix wifi TCP API server writing into dead sockets after reconnect
Guard TCP API writes after Wi-Fi reconnects
May 19, 2026
Contributor
There was a problem hiding this comment.
Pull request overview
This PR improves TCP-based API robustness by preventing StreamAPI/ServerAPI from continuing to write framed protobuf output to stale or non-writable WiFi/TCP clients after reconnects, reducing repeated write failures and log noise.
Changes:
- Refactors
StreamAPIframed output into a sharedwriteFrame()path and stops draining queued frames after a write failure. - Adds
ServerAPItransport-specific pre-write checks (disconnected / non-writable) and closes the client on pre-check failure or short writes. - Introduces a compile-time
availableForWrite()detection helper and adds unit tests for that helper logic.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/mesh/StreamAPI.h |
Adds frame-write hook points and changes emitTxBuffer() to return success/failure. |
src/mesh/StreamAPI.cpp |
Consolidates framing + write/flush into writeFrame() and aborts queue draining on failed writes. |
src/mesh/api/ClientWriteChecks.h |
New SFINAE-based helpers to detect and query availableForWrite() safely when present. |
src/mesh/api/ServerAPI.h |
Wires ServerAPI into the new StreamAPI frame-write hooks and includes the helper header. |
src/mesh/api/ServerAPI.cpp |
Implements pre-write readiness checks and closes/disables the API service on failures. |
test/test_client_write_checks/test_main.cpp |
Adds unit coverage for availableForWrite() detection and readiness helper behavior. |
Contributor
Author
|
Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details. Warning Firewall rules blocked me from connecting to one or more addresses (expand for details)I tried to connect to the following addresses, but was blocked by firewall rules:
If you need me to access, download, or install something from one of these locations, you can either:
|
Agent-Logs-Url: https://github.com/meshtastic/firmware/sessions/ebeb38d5-7339-4eac-b310-4b6dd9d40758 Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
Agent-Logs-Url: https://github.com/meshtastic/firmware/sessions/215c659d-bc17-4b30-89f4-78e3f9cdb3c3 Co-authored-by: thebentern <9000580+thebentern@users.noreply.github.com>
7e64dfe to
88426a4
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
🙏 Thank you for sending in a pull request, here's some tips to get started!
Problem
errno 11 (EAGAIN)write failures, noisy logs, and degraded API stability.Change
writeFrame()path inStreamAPI.ServerAPI:availableForWrite()is supportedavailableForWrite()so non-TCP / non-WiFi stream types keep existing behavior.Example
🤝 Attestations
Warning
Firewall rules blocked me from connecting to one or more addresses (expand for details)
I tried to connect to the following addresses, but was blocked by firewall rules:
api.registry.nm1.platformio.org/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_mqtt(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_mqtt -vvv(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_client_write_checks -vvv(dns block)api.registry.platformio.org/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_mqtt(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_mqtt -vvv(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_client_write_checks -vvv(dns block)collector.platformio.org/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_mqtt(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_mqtt -vvv(dns block)/home/REDACTED/.local/bin/pio /home/REDACTED/.local/bin/pio test -e native -f test_client_write_checks -vvv(dns block)If you need me to access, download, or install something from one of these locations, you can either: