-
Notifications
You must be signed in to change notification settings - Fork 30
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
supervised scopes do not run finalisers when used with never #174
Comments
I didn't verify but I guess there is an interrupted exception and that bypasses everything |
Can you try 0.3.0 & |
so if I try the exact same code then it still swallows the exception import ox.*
object launch extends OxApp.Simple:
def run(using Ox): Unit =
supervised:
releaseAfterScope:
??? // (here!)
never edit: actually now if I put a |
If I do my own little homebrew version - it seems the shutdown hook should be setup as soon as possible: import java.util.concurrent.atomic.AtomicReference
import java.util.concurrent.locks.LockSupport
import java.util.concurrent.Executors
class MyOx(val finalizers: AtomicReference[List[() => Unit]] = AtomicReference(List.empty))
def releaseAfterScope(using myox: MyOx)(f: => Unit): Unit =
myox.finalizers.updateAndGet((() => f) :: _)
inline def never: Nothing =
while true do
LockSupport.park()
if Thread.interrupted() then throw new InterruptedException()
???
def mysupervised(f: MyOx ?=> Unit): Unit =
val myox = MyOx()
try f(using myox)
catch
case e: InterruptedException =>
println("interrupted supervised")
Thread.currentThread().interrupt()
finally
println("finalizing supervised")
myox.finalizers.getAndSet(List.empty).foreach(_())
object Runner:
def main(args: Array[String]): Unit =
val thread = Thread.ofVirtual().start: () =>
mysupervised:
releaseAfterScope:
println("cancelled")
never
sys.addShutdownHook:
println("shutdown")
thread.interrupt()
thread.join()
println("shutdown done")
println("joining")
thread.join()
println("joined") running this:
|
Actually @adamw now with ox 0.3.0 and the OxApp the interruption does cause |
So the problem is with exceptions being thrown from finalizers? Where would you expect to see this exception? Not sure how to handle those ... when there's an interrupt, all forks that are running will end up with an exception. Most of these should be Maybe we should have another (overridable, or as part of |
I guess this is now a different issue - how to handle errors - so maybe this one can be considered fixed? - seems the JDK realises it's enough of an ambiguity to offer different kinds of error handling in its structured task scope https://docs.oracle.com/en/java/javase/21/core/structured-concurrency.html#GUID-2EF450F4-58CA-4D30-AF86-8AAB92B2AD16 |
Sure, we can open another issue then :) |
fixed by #175 |
The following pattern (used by Tapir's NettySyncServer
startAndWait
) seems to not respect finalisers of a scope if thenever
method is used.quitting an app with ctrl-c does not run the finaliser - or at least any side effect I tried such as printing does not appear to do anything.
So either this pattern should not be recommended if it is unsolvable (and fixed in Tapir), or there is a bug in the implementation.
The text was updated successfully, but these errors were encountered: