Repository navigation
perf: stop TLS retry storm, stream-parse JSON with a filter - #94
Merged
MatixYo merged 1 commit intoSep 24, 2026
Merged
Conversation
The 200 ms connect timeout was too short for a TLS handshake, so every poll retried handshakes in a loop until the 10 s deadline. Use a 5000 ms connect timeout and a single attempt; a stalled connect is retried by the next poll instead of blocking the UI. Parse the response straight off the socket with a DeserializationOption Filter that keeps only the rendered fields, instead of buffering the whole body into a String and parsing that. Drop performGetWithPoll and readResponseBodyWithPoll in favor of one httpGetJson helper. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017qjXYQiTkbgyVV7ZzvKzA3
MatixYo
approved these changes
Sep 24, 2026
lmoiseichuk
added a commit
to lmoiseichuk/ESP32-Plane-Radar
that referenced
this pull request
Oct 8, 2026
MatixYo#94 (e23b82c) stopped a TLS retry storm by replacing performGetWithPoll with a single GET and a 5000 ms connect timeout. When main was merged into MatixYo#90's branch (dc969f6, "Merge branch 'main' into feature/adsb-pipeline"), the conflict was resolved by keeping performGetWithPoll, and MatixYo#90 took it back to main (78958a5). It calls GET() again every 5 ms until a 6000 ms deadline whenever the result is CONNECTION_REFUSED or NOT_CONNECTED. A TLS setup that cannot allocate its record buffers comes back that way. mbedtls_ssl_setup fails with -32512 (SSL - Memory allocation failed), WiFiClientSecure::connect returns 0, and HTTPClient reports a refused connection. Nothing frees heap between attempts, so the same allocation fails every 5 ms until the deadline. The storm fires whenever the TLS setup cannot get its heap, or a connect is refused. On the 240x240 board the heap is there and it stays latent; it was seen on a fork driving a 360x360 panel, whose larger frame buffer leaves less heap. There each fetch repeated the failed allocation about 170 times, gave up after 6 s with "adsb: HTTP -11", and logged about 900 allocation failures a minute. Go back to MatixYo#94's behaviour: one GET with the 5000 ms connect timeout. A failed connect is retried by the next fetch, kAdsbFetchIntervalMs later. The background task, streaming parse and chunked framing from MatixYo#90 are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DL3fMjXoiVk9VGMHmQkfyW
lmoiseichuk
added a commit
to lmoiseichuk/ESP32-Plane-Radar
that referenced
this pull request
Oct 8, 2026
MatixYo#94 (e23b82c) stopped a TLS retry storm by replacing performGetWithPoll with a single GET and a 5000 ms connect timeout. When main was merged into MatixYo#90's branch (dc969f6, "Merge branch 'main' into feature/adsb-pipeline"), the conflict was resolved by keeping performGetWithPoll, and MatixYo#90 took it back to main (78958a5). It calls GET() again every 5 ms until a 6000 ms deadline whenever the result is CONNECTION_REFUSED or NOT_CONNECTED. A TLS setup that cannot allocate its record buffers comes back that way. mbedtls_ssl_setup fails with -32512 (SSL - Memory allocation failed), WiFiClientSecure::connect returns 0, and HTTPClient reports a refused connection. Nothing frees heap between attempts, so the same allocation fails every 5 ms until the deadline. The storm fires whenever the TLS setup cannot get its heap, or a connect is refused. On the 240x240 board the heap is there and it stays latent; it was seen on a fork driving a 360x360 panel, whose larger frame buffer leaves less heap. There each fetch repeated the failed allocation about 170 times, gave up after 6 s with "adsb: HTTP -11", and logged about 900 allocation failures a minute. Go back to MatixYo#94's behaviour: one GET with the 5000 ms connect timeout. A failed connect is retried by the next fetch, kAdsbFetchIntervalMs later. The background task, streaming parse and chunked framing from MatixYo#90 are unchanged. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01DL3fMjXoiVk9VGMHmQkfyW
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.
Two problems in the ADS-B fetch path, both visible as UI stalls on an ESP32-C3.
TLS retry storm. The connect timeout was 200 ms — far too short for a TLS handshake to opendata.adsb.fi.
performGetWithPolltherefore almost always failed and retried in a tight loop until the 10 s request deadline, opening a fresh handshake each time. Every poll cycle burned seconds of CPU and heap on handshakes that were killed just before they could finish. Now: 5000 ms connect timeout and a single attempt (kConnectAttempts = 1). If a connect stalls, the poll cycle gives up and the next one retries 3 s later, rather than blocking the display. ThepollNetwork()call before the GET is kept.Whole response buffered as a String.
readResponseBodyWithPollaccumulated the entire JSON body into a heapString, which was then parsed into aJsonDocument— the payload existed twice in RAM, and a busy sector's response is large. Replaced withdeserializeJson(doc, http.getStream(), DeserializationOption::Filter(filter)): ArduinoJson parses straight off the socket and the filter keeps only the fields actually rendered (lat,lon, headings, speeds, altitudes,flight,hex,t,category). No intermediate String, and the document holds a small fraction of the response.Also: request timeout 10000 ms to 6000 ms, and the now-unused
performGetWithPoll/readResponseBodyWithPollare deleted. The two paths are consolidated into onehttpGetJsonhelper.User impact: the radar stops freezing for seconds at a time on flaky WiFi, and peak heap use during a fetch drops substantially — the difference between working and heap-exhausting when many aircraft are in range.
Tested: builds for env:supermini; ran on an ESP32-C3 Super Mini + GC9A01 (combined with other local changes).
🤖 Generated with Claude Code
https://claude.ai/code/session_017qjXYQiTkbgyVV7ZzvKzA3