Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HttpServerRequest connection.close() does not trigger exceptionHandler() #5271

Open
marekscholle opened this issue Aug 2, 2024 · 1 comment
Labels

Comments

@marekscholle
Copy link

marekscholle commented Aug 2, 2024

Say we do something like this on HTTP server side with new HTTP request:

HttpServer server = vertx.createHttpServer(new HttpServerOptions().setTcpKeepAlive(true));
server.requestHandler(request -> {
  var n = 100;
  var chunk = new byte[512 * 1024];

  request.response()
    .putHeader("content-length", Integer.toString(n * chunk.length))
    .putHeader("content-type", "text/plain");

  for (int i = 0; i < n; i++) {
    request.response().write(Buffer.buffer(chunk));
  }

  // install exceptionHandler with expectation this will callback once server or client close connection
  request.response().exceptionHandler(e -> {
    LOGGER.info("exceptionHandler()");
  });

  // close the connection after 2s (as demonstration)
  vertx.setTimer(2000, unused -> {
    LOGGER.info("connection().close()");
    request.connection().close();
  });  
});

On client side, we read few bytes and then go idle, not consuming body but holding on connection. The client not accepting any data is critical piece here.

In Vert.x 3.x, the exceptionHandler() was triggered directly after server forcibly abort the request with request.connection().close().

However in Vert.x 4.x, we can see exceptionHandler() is triggered only after the client disconnects.

I found out that exceptionHandler() is not being called in Vert.x only if n is larger, so that some of write()s are pending in internal Vert.x queue – pending writes seems to block the effect of request.connection().close().

Is this expected? Is there other way to force close connection on server side? Thanks.

@marekscholle
Copy link
Author

marekscholle commented Aug 9, 2024

I found out it that ((Http1xServerConnection) request.connection()).channelHandlerContext().close(); seems to do what request.connection().close() used to do in Vert.x 3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant