Skip to content
Snippets Groups Projects
Commit e0f54d46 authored by Florian Fischer's avatar Florian Fischer
Browse files

[PipeSleepStrategy] fix specific state and sleeper count race

Introducing a lock for each specific state greatly simplifies the
algorithm, fixes a race and I expect it to be rather cheap.
The fact that we have to check two conditions before sleeping
and prepare resources dependent on those makes the algorithm
complex and racy.
We skip sleeping if we were notified specifically or the global sleeper
count was less than 0.

If we check our local state first and decrement the global sleeper count
later. We could receive a notification after the decrement which causes
the worker to skip sleeping making the decrement wrong and the whole counter
unsound.

Checking the local state first and mark us as sleeping preparing a
read for the specific pipe has the problem that after the decrement if we
should skip sleeping we have prepared sqes which we should submit needlessly
because we are not actually sleeping.

Ans decrementing the global count first has the same problem as the
first one where the decrement is wrong if we skip sleeping after wards
breaking the counter.

All this is prevented by locking the specific state while we check both conditions.
parent c57a23be
No related branches found
No related tags found
1 merge request!296fix Future::cancel with new Scheduler::scheduleOn(fiber, workerId)
Loading
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment