Skip to content

Commit adbdf40

Browse files
authored
fix(patch): [sc-870] Fix deadlock in the release build. (#118)
1 parent c15ba24 commit adbdf40

File tree

2 files changed

+11
-7
lines changed

2 files changed

+11
-7
lines changed

Sources/DistributedSystem/DistributedSystem.swift

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1033,32 +1033,36 @@ public class DistributedSystem: DistributedActorSystem, @unchecked Sendable {
10331033
// and it will entail a nested call to the resignID() for that actor,
10341034
// and we will have a recursive lock.
10351035
// Returning ActorInfo from under the lock let as release an actor instance outside the lock.
1036-
_ = lock.withLock { () -> ActorInfo? in
1037-
if let actorInfo = self.actors[id] {
1036+
let actorInfo: ActorInfo? = lock.withLock {
1037+
if let idx = self.actors.index(forKey: id) {
1038+
let actorInfo = self.actors[idx].value
10381039
switch actorInfo {
10391040
case .remoteClient:
10401041
fatalError("internal error: unexpected actor state")
10411042
default:
1042-
self.actors.removeValue(forKey: id)
1043+
self.actors.remove(at: idx)
10431044
return actorInfo
10441045
}
10451046
}
10461047
return nil
10471048
}
1049+
_ = actorInfo
10481050

10491051
if (id.channelID == 0) && ((id.instanceID & EndpointIdentifier.serviceFlag) != 0) {
10501052
let clientEndpointID = id.makeClientEndpoint()
1051-
_ = lock.withLock { () -> ActorInfo? in
1052-
if let actorInfo = self.actors[clientEndpointID] {
1053+
let actorInfo: ActorInfo? = lock.withLock {
1054+
if let idx = self.actors.index(forKey: clientEndpointID) {
1055+
let actorInfo = self.actors[idx].value
10531056
if case .newClient = actorInfo {
1054-
self.actors.removeValue(forKey: clientEndpointID)
1057+
self.actors.remove(at: idx)
10551058
return actorInfo
10561059
} else {
10571060
logger.error("internal error: unexpected actor state for \(clientEndpointID)")
10581061
}
10591062
}
10601063
return nil
10611064
}
1065+
_ = actorInfo
10621066
}
10631067
}
10641068

Tests/DistributedSystemTests/GenericDistributedActor.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ private distributed actor TestServiceEndpoint: ServiceEndpoint {
88
public typealias ActorSystem = DistributedSystem
99
public typealias SerializationRequirement = Transferable
1010

11-
static var serviceName = "TestService"
11+
static let serviceName = "TestService"
1212

1313
distributed func handleRequest() async throws {
1414
let clientEndpointID = id.makeClientEndpoint()

0 commit comments

Comments
 (0)