Skip to content

Commit

Permalink
Fix GenericRateLimiter hanging bug (#11763)
Browse files Browse the repository at this point in the history
Summary:
Fixes #11742

Even after performing duty (1) ("Waiting for the next refill time"), it is possible the remaining threads are all in `Wait()`. Waking up at least one thread is enough to ensure progress continues, even if no new requests arrive.

The repro unit test (bb54245e6) is not included as it depends on an unlanded PR (#11753)

Pull Request resolved: #11763

Reviewed By: jaykorean

Differential Revision: D48710130

Pulled By: ajkr

fbshipit-source-id: 9d166bd577ea3a96ccd81dde85871fec5e85a4eb
  • Loading branch information
ajkr authored and facebook-github-bot committed Aug 28, 2023
1 parent ba59751 commit 310a242
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed a race condition in `GenericRateLimiter` that could cause it to stop granting requests
20 changes: 10 additions & 10 deletions util/rate_limiter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -179,16 +179,16 @@ void GenericRateLimiter::Request(int64_t bytes, const Env::IOPriority pri,
// Whichever thread reaches here first performs duty (2) as described
// above.
RefillBytesAndGrantRequestsLocked();
if (r.request_bytes == 0) {
// If there is any remaining requests, make sure there exists at least
// one candidate is awake for future duties by signaling a front request
// of a queue.
for (int i = Env::IO_TOTAL - 1; i >= Env::IO_LOW; --i) {
std::deque<Req*> queue = queue_[i];
if (!queue.empty()) {
queue.front()->cv.Signal();
break;
}
}
if (r.request_bytes == 0) {
// If there is any remaining requests, make sure there exists at least
// one candidate is awake for future duties by signaling a front request
// of a queue.
for (int i = Env::IO_TOTAL - 1; i >= Env::IO_LOW; --i) {
auto& queue = queue_[i];
if (!queue.empty()) {
queue.front()->cv.Signal();
break;
}
}
}
Expand Down

0 comments on commit 310a242

Please sign in to comment.