-
Notifications
You must be signed in to change notification settings - Fork 2.1k
RFC: Replace finalization by cleaners
Vert.x 4 relies on Java finalization to close resources that have not been closed explicitly such as HTTP, TCP or SQL clients, as well as worker executors.
Java finalization has been deprecated for removal in JEP 421 and, Vert.x should replace them with cleaners introduced in Java 9.
When a Vert.x resource becomes unreachable , it should be disposed in a way that let the opportunity to the resource to be disposed in a graceful fashion:
- a client can end interactions with servers instead of closing the sockets abruptly
- the worker executor should finish to execute the worker tasks and fail the pending tasks not yet executed
To achieve this, Vert.x resource should implement a graceful termination using a configurable procedure.
- replace vertx finalizer usage by Java cleaner
- describe and implement a close sequence for Vert.x TCP clients
- provide a close sequence for all Vertx resources (e.g servers), this might be done but in a separate effort, this effort requires to introduce client shutdown in order to replace finalization by cleaners.
Vert.x 4 uses a close future object for two purposes:
- dependency tracking that cascades close resources (e.g closing a instance Vertx closes each HTTP client created from this instance)
- cleanup resource when the close future is collected
The close sequence is a multi steps procedure
- when a client initiates the close sequence
- it will not create new connections to the server
- existing connections are disposed gracefully
- after existing connections are disposed
- the client is closed
- all resources are released
The close sequence relies on a timeout to cease activity when the timeout deadline expires.
The close sequence can be triggered
- by the close method when the developer invokes it
- by the cleaner when the client is collected
- by the closeable reference when the parent context is disposed, such as verticle undeployment or on vertx instance close