Open jasagredo opened 1 week ago
The attached trace contains:
0s - Thread [].2 main - TxCommitted [] [TMVarId 2] Effect { }
while the code snippet doesn't mentions any TMVar
s, is this a bug in the recent feature or have you used TMVar
s in some version?
ok, the TMVar
s come from async
calls.
For me the property fails with a Deadlock
when I comment out the writeTQueue
action.
Yes, the problem is that the code with the writeTQueue still exhibits the race condition and IOSimPOR suddenly stops being able to find it
After chatting with @rjmh this might be a symptom of our implementation of MVars in terms of STM might be too deterministic and hides races.
Here's a direct quote:
Getting the race detection and reversal right between STM transactions is already pretty complex. Needing to handle MVars as primitives too would add a lot of complexity to IOSimPOR internals. If there is an implementation in terms of TVars--which has the same races--then using it will be simpler. I suppose there might be specific race reversals that needn't be explored with MVars... say a takeMVar which blocks, followed by a putMVar which unblocks it... but which the TVar implementation might classify as races anyway. If there are such cases, and they can't be fixed by rewriting the implementation-in-terms-of-TVars, then it might be worth making them atomic I suppose.
The present implementation keeps a list of blocked threads in the MVar (or rather, TVars which, when written, unblock a thread). But this means that even a takeMVar which blocks, or a putMVar which blocks, is implemented using a write to the TVar. That means that two blocking takeVars, for example, will be considered to race, because they write to the same TVar. Better would be for takeMVar to use STM retry to block the caller if the MVar is empty, thus turning blocking takeMVar calls (and similarly, blocking putMVar calls) into read-only transactions, that at least would not race with each other.
Although this situation is not ideal, i.e. IOSimPOR should still be able to find the races, this might be not a bug in IOSimPOR itself but rather a consequence of the MVar implementation
Describe the bug This test case:
will succeed. However removing the
atomically $ writeTQueue tq ()
will make it fail because of a Deadlock. The deadlock is indeed present in the implementation: t1 takes, t1 puts, t1 receives exception, t2 takes, t1 tryPut succesfully, t2 blocks on put.Writing to that tqueue before running the
bracketOnError
results in the race not being found by IOSimPOR. This looks like a direct bug.Desktop (please complete the following information):
GHC
version: 9.6.6io-sim
version: 1.6.0.0io-classes
version: 1.7.0.0Additional context Add any other context about the problem here. Attach
io-sim
orio-sim-por
trace if possible.A trace with the deadlock if removing the mentioned line: fail.txt