jetty / jetty/jetty.project

Improve connection closing when stopping

Open
#12,435 6 comments 0 reactions 0 assignees View on GitHub
Bug
Dominant language
Java
Stars
4.1k
Forks
2k
Avg merge
3d 56m
Merged PRs (30d)
48

Description

**Jetty version(s)**
12

**Description**
When stopping a `Server`, the `ManagedSelector` is stopped (as part of being a descendant bean of `Server`).

Currently, `ManagedSelector.doStop()` submits a `CloseConnections` update, and then waits for it, then submits a `StopSelector` update, and waits for it.

Both these updates iterate over the keys to call `close()`, but likely the `close()` operation is asynchronous -- it certainly is in HTTP/2 where a GOAWAY frame is submitted to be written, but it is also in HTTP/1 after the changes in #12395.

The idea would be to have a "pre-close" action, and we can use `Graceful` to shutdown and receive back a `CompletableFuture`.
So, the `CloseConnections` update would call `shutdown()` on the `Connection`, and the `StopSelector` action would call `EndPoint.close()`.
This would allow for asynchronous actions to happen in `Connection.shutdown()` and be waited for by `ManagedSelector`, and for `EndPoint.close()` to forcibly close.

The alternative would be to make the action in `[HTTP1,2,3]Connection.close()` to be run synchronously, but it may block.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.