Skip to content

Client: use OS default socket buffer sizes (fixes dropped QoS2 messages with large payloads) - #2278

Open
Romain-OD wants to merge 1 commit into
dotnet:masterfrom
Romain-OD:fix/2234-tcp-buffer-size
Open

Romain-OD wants to merge 1 commit into
dotnet:masterfrom
Romain-OD:fix/2234-tcp-buffer-size

Conversation

@Romain-OD

Copy link
Copy Markdown

Fixes #2234

Root cause

MqttClientTcpOptions.BufferSize defaulted to 8192 and was always applied to Socket.ReceiveBufferSize/SendBufferSize. Setting a fixed small SO_RCVBUF disables TCP receive-window auto-tuning, so a 200 KB payload needs many round trips. Under sustained QoS 2 load the subscriber falls behind and Mosquitto (default max_queued_messages 1000) silently drops queued messages (Outgoing messages are being dropped for client ...). The connection stays up and the client sees no error.

Fix

BufferSize now defaults to 0 = keep OS defaults. Explicit values > 0 are still applied as before.

Verification

Reporter's repro (ooredm/mqtt-bug), Mosquitto 2.0.15 default config, 10,000 × 200 KB QoS 2, Windows, .NET 10:

Client Received Broker drops
MQTTnet master (8 KB buffer) 4,415 yes
MQTTnet BufferSize = 65536 8,936 yes
paho-mqtt 10,000 no
MQTTnet this PR (OS default) 10,000 (2 runs, ~2.4–4.5k msg/s) no

Test suite: 507/509 pass. The 2 failures (Disconnect_Event_Contains_Exception, Invalid_Connect_Throws_Exception) fail identically on master in my environment (network/DNS dependent).

A fixed 8 KB SO_RCVBUF disabled TCP receive window auto-tuning and throttled
large payload throughput, causing brokers to drop queued messages for slow
subscribers.

Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Subscriber stops receiving mid-run with QoS2 and 200KB payloads (still connected, no errors)

1 participant