Skip to content

Commit ce2c82a

Browse files
ktosodrexin
authored andcommitted
=backtrace #61 make use of swift-backtrace (#62)
1 parent 43b702e commit ce2c82a

File tree

4 files changed

+14
-2
lines changed

4 files changed

+14
-2
lines changed

Package.swift

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ let targets: [PackageDescription.Target] = [
1515
"SwiftProtobuf",
1616

1717
"Logging", "Metrics",
18+
"Backtrace",
1819

1920
"DistributedActorsConcurrencyHelpers",
2021
"CDistributedActorsMailbox",
@@ -152,8 +153,10 @@ let dependencies: [Package.Dependency] = [
152153
.package(url: "https://github.com/apple/swift-log.git", from: "1.0.0"),
153154
.package(url: "https://github.com/apple/swift-metrics.git", from: "1.0.0"),
154155

156+
.package(url: "https://github.com/ianpartridge/swift-backtrace.git", .branch("master")),
157+
155158
// ~~~ only for samples ~~~
156-
.package(url: "https://github.com/MrLotU/SwiftPrometheus", .branch("master")),
159+
.package(url: "https://github.com/MrLotU/SwiftPrometheus", .branch("master"))
157160
]
158161

159162
let package = Package(

Sources/DistributedActors/ActorSystem.swift

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
//
1313
//===----------------------------------------------------------------------===//
1414

15+
import Backtrace
1516
import CDistributedActorsMailbox
1617
import Dispatch
1718
import DistributedActorsConcurrencyHelpers
@@ -124,6 +125,11 @@ public final class ActorSystem {
124125
var settings = settings
125126
self.name = settings.cluster.node.systemName
126127

128+
// rely on swift-backtrace for pretty backtraces on crashes
129+
if settings.installSwiftBacktrace {
130+
Backtrace.install()
131+
}
132+
127133
// TODO: we should not rely on NIO for futures
128134
let eventLoopGroup = MultiThreadedEventLoopGroup(numberOfThreads: settings.threadPoolSize)
129135
settings.cluster.eventLoopGroup = eventLoopGroup

Sources/DistributedActors/ActorSystemSettings.swift

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,9 @@ public struct ActorSystemSettings {
4343
}
4444
}
4545

46+
/// Installs a global backtrace (on fault) pretty-print facility upon actor system start.
47+
public var installSwiftBacktrace: Bool = true
48+
4649
// FIXME: should have more proper config section
4750
public var threadPoolSize: Int = ProcessInfo.processInfo.activeProcessorCount
4851
}

Sources/DistributedActors/Cluster/ClusterShellState.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ extension ClusterShellState {
178178

179179
switch state {
180180
case .initiated(let initiated):
181-
assert(initiated.channel != nil, "Channel should always be present after the initial initialization.")
181+
assert(initiated.channel != nil, "Channel should always be present after the initial initialization, state was: \(state)")
182182
_ = initiated.channel?.close()
183183
case .wasOfferedHandshake:
184184
fatalError("abortOutgoingHandshake was called in a context where the handshake was not an outgoing one! Was: \(state)")

0 commit comments

Comments
 (0)