Skip to content

Commit 8b5c377

Browse files
authored
Revert "Install shutdown signal hooks as LifecycleTask (#88)" (#90)
motivation: start handlers should not actually be part of the initialization process, as it breaks composition between ServiceLifecycles changes: This reverts commit dce53aa.
1 parent dce53aa commit 8b5c377

File tree

1 file changed

+4
-11
lines changed

1 file changed

+4
-11
lines changed

Sources/Lifecycle/Lifecycle.swift

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,6 @@ public struct LifecycleShutdownHandler<State> {
183183
/// By default, also install shutdown hooks based on `Signal` and backtraces.
184184
public struct ServiceLifecycle {
185185
private static let backtracesInstalled = AtomicBoolean(false)
186-
private static let shutdownHooksInstalled = AtomicBoolean(false)
187186

188187
private let configuration: Configuration
189188

@@ -202,7 +201,6 @@ public struct ServiceLifecycle {
202201
self.underlying = ComponentLifecycle(label: self.configuration.label, logger: self.configuration.logger)
203202
// setup backtraces as soon as possible, so if we crash during setup we get a backtrace
204203
self.installBacktrace()
205-
self.installShutdownHooks()
206204
}
207205

208206
/// Starts the provided `LifecycleTask` array.
@@ -214,6 +212,7 @@ public struct ServiceLifecycle {
214212
guard self.underlying.idle else {
215213
preconditionFailure("already started")
216214
}
215+
self.setupShutdownHook()
217216
self.underlying.start(on: self.configuration.callbackQueue, callback)
218217
}
219218

@@ -223,6 +222,7 @@ public struct ServiceLifecycle {
223222
guard self.underlying.idle else {
224223
preconditionFailure("already started")
225224
}
225+
self.setupShutdownHook()
226226
try self.underlying.startAndWait(on: self.configuration.callbackQueue)
227227
}
228228

@@ -247,16 +247,9 @@ public struct ServiceLifecycle {
247247
}
248248
}
249249

250-
private func installShutdownHooks() {
251-
if self.configuration.shutdownSignal != nil, ServiceLifecycle.shutdownHooksInstalled.compareAndSwap(expected: false, desired: true) {
252-
self.register(label: "Shutdown hooks",
253-
start: .sync(self.installShutdownSignalHooks),
254-
shutdown: .none)
255-
}
256-
}
257-
258-
private func installShutdownSignalHooks() {
250+
private func setupShutdownHook() {
259251
self.configuration.shutdownSignal?.forEach { signal in
252+
self.log("setting up shutdown hook on \(signal)")
260253
let signalSource = ServiceLifecycle.trap(signal: signal, handler: { signal in
261254
self.log("intercepted signal: \(signal)")
262255
self.shutdown()

0 commit comments

Comments
 (0)