Skip to content

Commit

Permalink
handle race in RegexMatchCache is-ready and prepare sequence
Browse files Browse the repository at this point in the history
Summary:
The race is when two threads both do:
```
// hold shared lock
if (!cache.isReadyToFindMatches(key)) {
  // drop shared lock
  // acquire exclusive lock
  cache.prepareToFindMatches(key);
  // transition exclusive to shared lock
}
```

Differential Revision: D64149453

fbshipit-source-id: b8ed1c85a4d73f259c0b7aa4c2b5ed82d8474d6c
  • Loading branch information
yfeldblum authored and facebook-github-bot committed Oct 10, 2024
1 parent a1cf715 commit 95fcdbf
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion folly/container/RegexMatchCache.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,11 @@ void RegexMatchCache::prepareToFindMatches(regex_key_and_view const& regex) {
} else {
// evaluate old regex over queue
auto const sqriter = stringQueueReverse_.find(regexp);
CHECK(sqriter != stringQueueReverse_.end());
if (sqriter == stringQueueReverse_.end()) {
// was actually ready-to-find-matches for regex
guard.dismiss();
return;
}
auto const strings = std::move(sqriter->second.strings);
CHECK(!strings.empty());
stringQueueReverse_.erase(sqriter);
Expand Down

0 comments on commit 95fcdbf

Please sign in to comment.