Repository navigation
Fix race condition getting optimizers stuck, leaving collection in yellow state - #5111
Conversation
tellet-q
left a comment
There was a problem hiding this comment.
lgtm, we ran a test to check if the log line appears and it did
| .into_iter() | ||
| .rev() | ||
| .map(|i| handles.remove(i)) | ||
| .map(|i| handles.swap_remove(i)) |
There was a problem hiding this comment.
Using swap_removes means losing ordering of handles.
Just want to confirm that it is not something we care about :)
There was a problem hiding this comment.
It doesn't matter, but thanks for confirming!
We only keep the handles to count the tasks that are still ongoing, and to catch any panics. Tasks themselves run asynchronously in their own thread. We don't care in what order or at what time we clean them up.
| // Skip if we reached limit, an ongoing optimization that finishes will trigger this loop again | ||
| let limit = max_handles.saturating_sub(optimization_handles.lock().await.len()); | ||
| if limit == 0 { | ||
| log::trace!("Skipping optimization check, we reached optimization thread limit"); |
There was a problem hiding this comment.
I never use trace because it is way too verbose.
Would it make sense to bump this one to debug?
There was a problem hiding this comment.
It can happen a lot and cause a lot of log spam in debug. A lot as in, with every update operation you send. That's why we demoted it a long time ago to trace.
It actually was useful in our benchmarking setup a few days ago where we changed logging to trace just to confirm some branches were hit.
Do you think setting it to debug would be worth the log spam?
There was a problem hiding this comment.
Let's keep it to trace if it is noisy 👍
There was a problem hiding this comment.
Less noisy than I remembered. Still noisy enough though.
Screencast.from.2024-09-23.10-40-58.mp4
…llow state (#5111) * Return whether any task was cleaned * Retrigger optimizers after cleanup timeout if we cleared a handle * Flatten match used as decision logic on whether to run optimizers * Add comment to elaborate we have a branch to prevent race condition * Rename force to ignore_max_handles * Use swap remove as it is a bit more efficient
This PR fixes a race condition which would allow the optimizers for a collection to get stuck. The result is a collection that remains in yellow state forever, unless a new update operation is send to trigger the remaining optimizations.
The PR has two changes:
continue/break.The data race is caused by an ordering problem between three things:
Basically, we trigger the optimizers again before cleaning the finished handle up (through a callback). If checking the maximum allowed handles on a new run, we'd still be at the maximum, cancelling the new optimization. There are no other ongoing optimizations to trigger the optimizer loop once again, getting it stuck. In other words, the problem is that we retrigger optimizations before cleaning up the handles. Sadly that's not an easy thing to fix.
This PR patches the problem by triggering optimizations even if we clean up any finished handles. This means we pass the handle limit condition, which prevents it getting stuck. We have tested this patch on our benchmark server. It has shown to solve the problem.
I'm not super satisfied with the way the optimization loops works right now. I suggest to merge this PR, and attempt to refactor it separately to make this data race impossible.
Details
We did not catch this before because we have no optimization handle limit by default. In case of our benchmark server we have a limit of 1 set however.
Detailed scenario, in order:
This PR patches point 8.
All Submissions:
devbranch. Did you create your branch fromdev?New Feature Submissions:
cargo +nightly fmt --allcommand prior to submission?cargo clippy --all --all-featurescommand?