Skip to content

NetSocket.endHandler called too early before all data is read (fires with closeHandler) #5748

@jingyu

Description

@jingyu

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

  1. Create a simple TCP server that sends a large data block (e.g. ≥ 1 MB) and then closes the connection.
  2. 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"));
         }
     });
  3. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions