ox
ox copied to clipboard
Scope finalizers don't run on runtime shutdown
Ox offers a nice way to manage resources in scopes:
supervised {
val serverBinding = useInScope(NettySyncServer().addEndpoints(endpoints).start())(_.stop())
//...
never
}
The release clause (_.stop()
) is run only if the scope fails due to an unhandled exception. We often deal with long-living resources which should get released on server shutdown, which typically means a TERM signal to the JVM, handled by a shutdown hook.
This is handled in Cats Effect by IOApp
, where users can compose resources into a final effectIO[ExitCode]
. In case of runtime shutdown,main fiber will be canceled and resource finalizers will be called.
Maybe we can somehow achieve a similar effect in Ox? There is no notion of App
, main fiber
etc., but I'm leaving this issue as a remark that using resources in scopes has this particular limitation.