Repository navigation
Conversation
This was referenced Oct 19, 2026
Contributor
|
this looks like a valid fix, but should be fixed upstream in the owner's project at https://github.com/bertmelis/espMqttClient . Please do a PR there. |
Contributor
Author
|
This one is only a setting in EMS-ESP's |
The 1440 byte receive buffer only works when the broker honours the TLS max fragment length extension the client asks for. A broker that ignores it (Go crypto/tls, for example) sends records of up to 16 KB and the connection fails on the first one that does not fit. Behind ghostunnel this happened mid-stream once the broker had sent a few hundred messages. ESP_SSLClient allocates its buffers in PSRAM (ENABLE_PSRAM), so on boards that have it use a 16 KB receive buffer. Boards without PSRAM keep the small buffer.
csutcliff
force-pushed
the
pr/mqtt-tls-rx-buffer
branch
from
October 20, 2026 11:55
16efaf8 to
aee80ab
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.
Problem
The MQTT TLS client uses a 1440 byte receive buffer (plus BearSSL's 325 bytes of overhead). That only works because BearSSL then asks the broker, through the TLS max fragment length extension, to keep records small. mosquitto (OpenSSL) honours it. A broker that ignores it can send records of up to 16 KB, and the first one that doesn't fit ends the connection.
Reproduced with ghostunnel (Go's crypto/tls, which doesn't implement max fragment length) in front of mosquitto, and an RSA-4096 chain. The handshake works. Go's crypto/tls keeps records small at the start of a connection, and once it stops, EMS-ESP drops the connection (
MQTT connection failure: TCP) and reconnects. In the test that happened after 61 KiB of a burst of 300 x 1 KB messages.Fix
ESP_SSLClient already allocates its buffers in PSRAM when the build has
BOARD_HAS_PSRAMandENABLE_PSRAM(both set for PSRAM builds). On those boardsClientSecureSyncnow asks for a 16 KB receive buffer, the TLS maximum. Boards without PSRAM keep 1440 bytes, so their internal heap is untouched.Testing
Same ghostunnel setup and flood (300 x 1 KB, then 20 x 8 KB):
s_16M_P, clang-format clean.The test broker ran on port 18883, which needs #3302 to get TLS at all. On a port from ESP_SSLClient's list this fix stands alone. Other MQTT TLS fixes: #3300, #3301.
Checklist
devbranch.clang-formatCHANGELOG_LATEST.mdupdated