-
Notifications
You must be signed in to change notification settings - Fork 2.1k
Open
Description
Version
5.0.4
Context
When using NetSocket with flow control (pause() / resume()), the endHandler is sometimes invoked too early, before all buffered data has been delivered to the read handler.
According to the Javadoc, the endHandler should be called after all data has been read, and possibly even after the closeHandler only if the socket is paused and there are still buffers to deliver.
However, in Vert.x 5.x (4.5.x is good), the endHandler is triggered at the same time as the closeHandler, effectively before all data is drained, which contradicts the documented behavior.
Steps to reproduce
- Create a simple TCP server that sends a large data block (e.g. ≥ 1 MB) and then closes the connection.
- Create a client that connects and reads with flow control
vertx.createNetClient().connect(9000, "localhost", ar -> { if (ar.succeeded()) { NetSocket socket = ar.result(); socket.handler(buf -> { System.out.println("Received " + buf.length() + " bytes"); socket.pause(); vertx.setTimer(50, t -> socket.resume()); }); socket.endHandler(v -> System.out.println(">>> endHandler fired")); socket.closeHandler(v -> System.out.println(">>> closeHandler fired")); } });
- Run several times.
You will often see endHandler fired at the same time as closeHandler, and sometimes before the client receives all data.
Do you have a reproducer?
No response