Skip to content

Commit 350e2e0

Browse files
committed
Only cancel server on network disconnect if container running.
1 parent 4d7a662 commit 350e2e0

1 file changed

Lines changed: 7 additions & 4 deletions

File tree

Sources/Services/ContainerSandboxService/Server/SandboxService.swift

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -949,8 +949,8 @@ public actor SandboxService {
949949
metadata: ["network": "\(networkId)"]
950950
)
951951
// Attempt graceful container cleanup under the lock before exiting.
952-
await self.lock.withLock { _ in
953-
guard let ctrInfo = await self.container else { return }
952+
let shouldCancel = await self.lock.withLock { _ -> Bool in
953+
guard let ctrInfo = await self.container else { return false }
954954
switch await self.state {
955955
case .running, .booted:
956956
await self.setState(.stopping)
@@ -963,13 +963,16 @@ public actor SandboxService {
963963
)
964964
}
965965
await self.setState(.stopped)
966+
return true
966967
default:
967-
break
968+
return false
968969
}
969970
}
970971
// Cancel the main XPC connection. This causes the XPC server's listen() to return,
971972
// unwinding the task group in RuntimeLinuxHelper and exiting the process.
972-
xpc_connection_cancel(self.connection)
973+
if shouldCancel {
974+
xpc_connection_cancel(self.connection)
975+
}
973976
}
974977

975978
private func getDefaultNameservers(networkConfigs: [AttachmentConfiguration]) async throws -> [String] {

0 commit comments

Comments
 (0)