Skip to content

Commit 3fe58da

Browse files
bkonyiCommit Queue
authored andcommitted
[ DDS ] Fix race condition in Mutex
The lock was being released but not reacquired when the next request resumed, potentially leading to a race. Change-Id: Ib00ae40ca8c1dfff6b98bbf642032c57d498fa40 Reviewed-on: https://dart-review.googlesource.com/c/sdk/+/394760 Auto-Submit: Ben Konyi <[email protected]> Reviewed-by: Jessy Yameogo <[email protected]> Commit-Queue: Ben Konyi <[email protected]>
1 parent 07148b7 commit 3fe58da

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

pkg/dds/lib/src/utils/mutex.dart

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,11 +72,15 @@ class Mutex {
7272
}
7373

7474
void _releaseLock() {
75-
_locked = false;
7675
if (_outstandingRequests.isNotEmpty) {
7776
final request = _outstandingRequests.removeFirst();
7877
request.complete();
78+
return;
7979
}
80+
// Only release the lock if no other requests are pending to prevent races
81+
// between the next request from the queue to be handled and incoming
82+
// requests.
83+
_locked = false;
8084
}
8185

8286
int _weakGuards = 0;

0 commit comments

Comments
 (0)