WIP: Ensure restarts cancel outstanding shake threads - #5021
Conversation
|
The approach is to introduce a centralized management on the asyncs for the database if I understand correctly. Take a look at the work replacing the decentralized AIO entirely at #4927 @crtschin |
This does introduce management of asyncs, which previously only existed in pure thunks. Though I wouldn't call
That should be fine as the function is recursive until it settles. So even if threads were spawned in the timespan before they died,
I tried looking at the PR, but there are a lot of moving bits, and is a bit hard to understand what was going on 😅. I want to avoid large-scale refactors if possible. I'll give it a second pass and try to post some probing questions.
I don't know what you have in mind, so maybe! |
Yes, it contains a lot of exprimental improvements.
As we discuss in #4988, leaking AIO thread is the problem, so a lingering thread won't be killed by any parent. So it is still possible to escape from interleaving |
| cancelTrackedAsyncs Database{..} = | ||
| let go = do | ||
| as <- atomically $ IntMap.elems . snd <$> readTVar databaseAsyncs | ||
| unless (null as) $ do |
There was a problem hiding this comment.
Perhaps we should guard the databaseAsyncs here, so no new async would be created in between readTVar databaseAsyncs and killing them. Then we can ensure no one leak ?
|
I got an idea to fix the AIO leaking bug @crtschin, add a switch for AIO, when the thread that have the scope exit, we flip the switch that would halt any future registration. Then we won't have lingering threads that won't be killed by a session restart. |
Trying to understand what you mean here. So adding a guard to |
|
I mean attacking the bug directly #4988 (comment), then we do not need the extra bookeeping of threads. more presicely, close the possiblility to register a new async in |
|
I see, so avoiding threads from being spawned in the first place when a restart occurs, instead of trying to track/find and kill them. |
|
Superceded by #5027 |
Reattempt and fixes #4985
The previous approach used a guard added to every shake thread to check whether the rule evaluated an outdated value. That approach was incomplete as the core issue is that the thread shouldn't have survived to execute.
This PR takes a different approach tracks every spawned thread and does a cancellation when a restart occurs.