Skip to content

Pause/Resume read from Socket - branch 4.x#261

Merged
vietj merged 1 commit intovert-x3:4.xfrom
dometec:4.x
Feb 17, 2026
Merged

Pause/Resume read from Socket - branch 4.x#261
vietj merged 1 commit intovert-x3:4.xfrom
dometec:4.x

Conversation

@dometec
Copy link
Contributor

@dometec dometec commented Jan 25, 2026

PR for the old #6 :)

I want to pause reading from the socket to avoid being overwhelmed by QoS 0 messages.
When reading is paused, incoming data accumulates in the TCP receive buffer. As the buffer fills up, the TCP stack advertises a reduced window size (eventually a zero window) to the broker, applying backpressure at the TCP level.

At that point, outgoing data may accumulate in the broker’s socket send buffer until its limits are reached. Depending on the broker implementation and configuration, QoS 0 messages that cannot be written may be buffered or dropped.

@vietj
Copy link
Contributor

vietj commented Jan 26, 2026

I think this should use instead NetSocket pause / resume instead

@dometec
Copy link
Contributor Author

dometec commented Jan 26, 2026

It doesn’t have the same effect, in fact, it has no effect at all.
NetSocket.pause() switches the internal InboundBuffer into fetch mode, but this buffer is never actually used because MqttClientImpl sets a messageHandler instead of a handler, effectively bypassing the InboundBuffer backpressure mechanism.

I tried to simply replace messageHandler with handler here:

soi.messageHandler(msg -> this.handleMessage(soi.channelHandlerContext(), msg));

but doing so resulted in no messages being delivered at all.

If you think this is the correct direction, let me know and I’ll spend some more time understanding where the missing piece is.

@vietj
Copy link
Contributor

vietj commented Jan 27, 2026

right, this is because messages are not accounted by back pressure and I think only works in master.

can you make a PR for master and use pause/resume so we check that ?

I would like to determine what is the long term viable option for this.

@dometec
Copy link
Contributor Author

dometec commented Jan 30, 2026

on master it works with NetSocket, see PR #262

Let me know how to proceed for this PR on 4.x branch

@dometec dometec changed the title Pause/Resume read from Socket Pause/Resume read from Socket - branch 4.x Jan 31, 2026
@vietj
Copy link
Contributor

vietj commented Feb 12, 2026

the tests seem to do very large pause with the timers, is that possible to have a test that takes less time ?

@dometec
Copy link
Contributor Author

dometec commented Feb 13, 2026

pause reduced, like for 5.0 branch, I had to update testcontainer to pass the CI

Motivation:
The ability to pause reading from the socket to avoid being overwhelmed by QoS 0 messages during traffic spikes.
When reading is paused, incoming data accumulates in the TCP receive buffer. As the buffer fills up, the TCP stack advertises a reduced window size (eventually a zero window) to the broker, applying backpressure at the TCP level.
At that point, outgoing data may accumulate in the broker’s socket send buffer until its limits are reached. Depending on the broker’s implementation and configuration, QoS 0 messages that cannot be written may be buffered or dropped.

Changes:
Implement new pause/resume methods that change the setAutoRead(bool) connection's option.
@vietj vietj added this to the 4.5.26 milestone Feb 17, 2026
@vietj vietj merged commit 7a31582 into vert-x3:4.x Feb 17, 2026
4 checks passed
@vietj
Copy link
Contributor

vietj commented Feb 17, 2026

thanks @dometec can you provide a PR for master that also upgrades the test ?

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

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants