cats-effect icon indicating copy to clipboard operation
cats-effect copied to clipboard

Add `GenConcurrent#forceStart` that guarantees a fiber will start

Open bplommer opened this issue 3 years ago • 2 comments

The possibility of an uncancelable fiber being canceled before it starts executing is, I think, a surprising footgun for many people. If nothing else, adding this forceStart method will help raise awareness of that possibility.

bplommer avatar Aug 09 '22 16:08 bplommer

The test failure doesn't appear to be related to the contents of this PR:

[info] WorkerThreadNameSpec
[info] WorkerThread should
[error]   x rename itself when entering and exiting blocking region
[error]    the value is false (WorkerThreadNameSpec.scala:73)

bplommer avatar Aug 10 '22 08:08 bplommer

I'm kind of on the fence about this one, conceptually. Fibers are, fundamentally, three state objects: unstarted, started, and completed. Cancelation has different effects depending on which state the fiber is in (atomically), and this is just fundamental in the model. What this PR does is attempt to eliminate the first state from the calculus by blocking cancel until the fiber moves into the second state. This does work but it raises a lot of other questions around what you should do if the requisite blocking starts to become noticeably long. In other words, it's still a footgun, just of a different sort.

djspiewak avatar Sep 19 '22 07:09 djspiewak