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

API for graceful disposal in Disposable #3173

Open
chemicL opened this issue Aug 29, 2022 · 2 comments
Open

API for graceful disposal in Disposable #3173

chemicL opened this issue Aug 29, 2022 · 2 comments
Labels
status/need-design This needs more in depth design work type/enhancement A general enhancement
Milestone

Comments

@chemicL
Copy link
Member

chemicL commented Aug 29, 2022

Motivation

Disposable interface defines the void dispose() method, which is of eager nature and in most cases assumes non graceful, forceful release of underlying resources. There are cases where such an attempt is not desired. Other projects, like reactor-netty, or rsocket-java, have come up with their own abstractions for disposing resources related to connection and request management. In reactor-core, it was also necessary to support graceful disposal of implementations of Scheduler interface (#3089).

Desired solution

It looks that from the existing implementations, the following properties are desired:

  • lazily triggered
  • graceful (allows cleanup and timely termination of allocated resources)
  • observable and coordinated result
  • supports timeout and forceful termination in case the deadline passes
  • can support more timeout conditions, e.g. in case of reactor-netty there are two timeout values with different meanings

To list some examples:

reactor-netty in DisposableChannel:

reactor-netty in LoopResources:

rsocket-java uses the DisposableChannel from reactor-netty with its own Closeable interface:

I would argue it's possible to unify these efforts using following methods:

  • Mono<Void> disposeGracefully() as part of a new Disposable.Graceful interface,
  • Mono<Void> onDispose() potentially added to Disposable (breaking change) or a new interface, e.g. ListenableDisposable, which would become a parent of Disposable.Graceful.

The current Disposable already has

  • void dispose()
  • boolean isDisposed()

Together, they would form a base for extension using concepts specific to a particular use case, e.g. the quietPeriod and deadline in case of reactor-netty, could be expressed as Mono<Void> disposeGracefully(Duration deadline, Duration quietPeriod).

Considered alternatives

One alternative would be to assume different use cases have different needs and the unification effort is pointless. However, without a common denominator, the existing APIs differ even within the same project, potentially leading to inconsistencies and lack of easy-to-predict behaviors.

@reactorbot reactorbot added the ❓need-triage This issue needs triage, hasn't been looked at by a team member yet label Aug 29, 2022
@chemicL chemicL added type/enhancement A general enhancement status/need-design This needs more in depth design work and removed ❓need-triage This issue needs triage, hasn't been looked at by a team member yet labels Sep 20, 2022
@chemicL chemicL added this to the 3.5.0 planning milestone Sep 20, 2022
@chemicL
Copy link
Member Author

chemicL commented Sep 20, 2022

Scheduler restarts make it harder to implement having onDispose(). We should consider imposing a contract there to disallow restarts.

@chemicL
Copy link
Member Author

chemicL commented Oct 21, 2022

The deprecation of restarts is already happening via deprecation of the start() method and introduction of init() via #3202

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status/need-design This needs more in depth design work type/enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants