Comments (6)
Not entirely sure why that's not working in this instance.
It's working. The second iteration of the while loop executes the IO on a different IORuntime. But then the fatal failure handling code doesn't entirely run, because globalFatalFailureHandled
is already true.
from cats-effect.
It seems there are multiple things going on here. The essential thing is that when a fatal exception is detected (which InterruptedException
is), we're shutting down the whole world (meaning all the IORuntime
s in the current JVM).
There are incorrect things I see in the behavior of CE with the code above:
- The
IORuntime
doesn't seem to shut down cleanly. - There is a second
IORuntime
created, which also doesn't shut down cleanly.
These should be fixed, but fixing these won't make the code example "work", at least I don't think so: the idea is, that if there is a fatal exception, the most we can hope for is a clean shutdown.
What would you consider "correct behavior" for this code example?
from cats-effect.
So the tricky thing here is that InterruptedException
, like all fatal errors, fully torpedoes the runtime. By the time you get to the second iteration, the threads are all shut down and gone, so it's impossible to use global
to execute anything. The design expectation is that you're not going to try to execute anything after this point, and you'll basically just shut down the VM.
Of course, that's not what you want here since you're trying to run new things after we torpedo the runtime. The answer is probably for you to not use global
and instead make your own IORuntime
(probably using the builder). Whenever you catch and recover from a fatal error, build a new runtime for yourself and discard the old one.
from cats-effect.
So the tricky thing here is that
InterruptedException
, like all fatal errors, fully torpedoes the runtime. By the time you get to the second iteration, the threads are all shut down and gone, so it's impossible to useglobal
to execute anything
Hmm, but maybe we can fix this. We already made some changes so that when the global runtime shuts down, it removes itself so that a new one may be installed.
Not entirely sure why that's not working in this instance.
from cats-effect.
As per @durban comment creating the runtime on every iteration still causes the second iteration to not throw an exception outside of the IO.
while(true){
val (compute,_) = IORuntime.createWorkStealingComputeThreadPool()
val (blocking,_) = IORuntime.createDefaultBlockingExecutionContext()
val (scheduler,_) = IORuntime.createDefaultScheduler()
val ioRuntime = IORuntime.builder().set compute(compute, ()=>()).setBlocking(blocking, ()=>()).setScheduler(scheduler, ()=>()).build
val f = IO{
throw new InterruptedException("Test")
}.attempt.unsafeToFuture()(ioRuntime)
try{
Await.result(f, Duration.Inf)
} catch {
case t:ExecutionException => println(s"Underlyng exception ${t.getCause}")
}
}
To give some context to the implementation we are migrating from cats effect 2 to 3. Our current implementation runs the IO in separate threads which are managed via JMX so on an interrupted exception from the IO is caught in the thread, the interrupt reset and then continues.
Though not an ideal mechanism I was hoping with cats effect 3 we would just be able to keep the same handling to minimise the changes.
So a separate IORuntime for each thread. When interrupt is thrown it's caught in the main thread, resets interrupt, recreates IORuntime and continues.
from cats-effect.
There are incorrect things I see in the behavior of CE with the code above:
- The IORuntime doesn't seem to shut down cleanly.
This seems to be a bug, see #4066 and #4067.
from cats-effect.
Related Issues (20)
- better handling of callbacks that might throw in `CallbackStack` HOT 1
- Allow overriding how fatal errors are printed HOT 7
- Improve `MonadCancel` scaladoc HOT 4
- Cancelling `Async` queue `take` makes other `take` hang HOT 5
- `IO#asyncCheckAttempt` is inconsistent with `Async#asyncCheckAttempt`
- Improve contributor documentation HOT 3
- Add (best-effort) stealing API to polling system
- Add API to polling system to attempt to get current poller without shifting HOT 6
- More efficient monitoring of fibers on virtual threads HOT 1
- Published tutorial older than tutorial.md HOT 1
- OutOfMemoryError when IO.uncancelable is used in recursive function HOT 3
- unsafeToFutureCancelable's cancel future completes before setting the result future's cancellation status HOT 7
- Support for V8 JavaScript Engine? HOT 2
- IO.onError is inconsistent with ApplicativeError HOT 3
- `AsyncSpec` failure (ciJS)
- When `IORuntime.global` shuts down, it doesn't shut down the WSTP HOT 1
- Queued but unstarted work on `Dispatcher.sequential` should be cancelable HOT 6
- Release for Scala Native 0.5.x HOT 1
- Consolidate duplicate "currently executing fiber" pointers
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from cats-effect.