Skip to content

Commit

Permalink
loop shutdown should not call CancelRequest for inflight requests bec…
Browse files Browse the repository at this point in the history
…ause it causes a race with the code that's executing those requests, we should simply wait until those requests complete by themselves
  • Loading branch information
qkrorlqr committed May 14, 2024
1 parent 21446f8 commit 642be6e
Showing 1 changed file with 14 additions and 9 deletions.
23 changes: 14 additions & 9 deletions cloud/filestore/libs/vfs_fuse/loop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ class TCompletionQueue final
enum fuse_cancelation_code CancelCode;
NAtomic::TBool ShouldStop = false;
TAtomicCounter CompletingCount = {0};
TManualEvent RequestCompleted;
TManualEvent Stopped;

TMutex RequestsLock;
Expand Down Expand Up @@ -126,6 +127,8 @@ class TCompletionQueue final
CompletingCount.Add(1);
}

RequestCompleted.Signal();

int ret = cb(req);
if (CompletingCount.Dec() == 0 && ShouldStop) {
Stopped.Signal();
Expand All @@ -137,16 +140,18 @@ class TCompletionQueue final
CancelCode = code;
ShouldStop = true;

TGuard g{RequestsLock};
for (auto&& [req, context] : Requests) {
CancelRequest(
Log,
*RequestStats,
*context,
req,
CancelCode);
// we cannot cancel inflight requests because of a possible race
// between CancelRequest (which touches TCallContext and fuse_req_t)
// and natural request processing
while (true) {
with_lock (RequestsLock) {
if (Requests.empty()) {
break;
}
}

RequestCompleted.Wait();
}
Requests.clear();

while (CompletingCount.Val() != 0) {
Stopped.Wait();
Expand Down

0 comments on commit 642be6e

Please sign in to comment.