Skip to content

Commit 9da657e

Browse files
committed
-ub don't hold locks over suspension points
1 parent b78dec1 commit 9da657e

File tree

2 files changed

+7
-7
lines changed

2 files changed

+7
-7
lines changed

Sources/DistributedActors/ClusterSystem.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ public class ClusterSystem: DistributedActorSystem, @unchecked Sendable {
184184
// ==== ----------------------------------------------------------------------------------------------------------------
185185
// MARK: Shutdown
186186
private var shutdownReceptacle = BlockingReceptacle<Error?>()
187-
internal let shutdownLock = Lock()
187+
internal let shutdownSemaphore = DispatchSemaphore(value: 1)
188188

189189
/// Greater than 0 shutdown has been initiated / is in progress.
190190
private let shutdownFlag: ManagedAtomic<Int> = .init(0)
@@ -488,7 +488,7 @@ public class ClusterSystem: DistributedActorSystem, @unchecked Sendable {
488488
return Shutdown(receptacle: self.shutdownReceptacle)
489489
}
490490

491-
self.shutdownLock.lock()
491+
self.shutdownSemaphore.wait()
492492

493493
/// Down this member as part of shutting down; it may have enough time to notify other nodes on an best effort basis.
494494
if let myselfMember = self.cluster.membershipSnapshot.uniqueMember(self.cluster.uniqueNode) {
@@ -499,7 +499,7 @@ public class ClusterSystem: DistributedActorSystem, @unchecked Sendable {
499499

500500
self.log.log(level: .debug, "Shutting down actor system [\(self.name)]. All actors will be stopped.", file: #file, function: #function, line: #line)
501501
defer {
502-
self.shutdownLock.unlock()
502+
self.shutdownSemaphore.signal()
503503
}
504504

505505
if let cluster = self._cluster {

Sources/DistributedActors/Timers+Distributed.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -129,9 +129,9 @@ public final class ActorTimers<Act: DistributedActor> where Act.ActorSystem == C
129129
// Which may cause: Cannot schedule tasks on an EventLoop that has already shut down.
130130
// The actual solution is outstanding work tracking potentially.
131131
let system = self.actorSystem
132-
system?.shutdownLock.lock()
132+
system?.shutdownSemaphore.wait()
133133
defer {
134-
system?.shutdownLock.unlock()
134+
system?.shutdownSemaphore.signal()
135135
}
136136

137137
await call()
@@ -143,9 +143,9 @@ public final class ActorTimers<Act: DistributedActor> where Act.ActorSystem == C
143143
// Which may cause: Cannot schedule tasks on an EventLoop that has already shut down.
144144
// The actual solution is outstanding work tracking potentially.
145145
let system = self.actorSystem
146-
system?.shutdownLock.lock()
146+
system?.shutdownSemaphore.wait()
147147
defer {
148-
system?.shutdownLock.unlock()
148+
system?.shutdownSemaphore.signal()
149149
}
150150

151151
await call()

0 commit comments

Comments
 (0)