16 Commits
Author SHA1 Message Date
Daiki Matsudate 65771b62e7 Drop @unchecked from UnixSignalsSequence.Storage's Sendable conformance (#265)
### Motivation

`UnixSignalsSequence.Storage` is marked `@unchecked Sendable`, but its
stored properties are `let stateMachine: LockedValueBox<StateMachine>`
and `let sources: [Source]` (where `Source` is already checked
`Sendable`). The compiler can verify this conformance, and keeping
`@unchecked` means it would not catch a future change that breaks
sendability.

### Modifications

- Replace `@unchecked Sendable` with `Sendable` on
`UnixSignalsSequence.Storage`.

### Result

No behavior change; the conformance is now checked by the compiler.

Verified locally on macOS (Swift 6.4.2): `swift build --build-tests
-Xswiftc -strict-concurrency=complete` produces no new diagnostics and
`swift test` passes. Linux is left to CI.
2026-10-30 14:27:13 +01:00
Muhammadjon Marufov 5e3b0e9a1e Fix dispatch source leaks in UnixSignalsSequence (#258)
Fixes #256.

## Motivation

`UnixSignalsSequence` keeps dispatch signal sources alive after the
sequence and its iterator are released. The event handler captures the
whole `Source` value, which holds the `DispatchSource`, creating a
retain cycle.

## Modifications

- Keep the sources on `Storage` and cancel them in `deinit`.
- Resume sources skipped when initialization is cancelled so libdispatch
can run cancellation cleanup and release their handlers.
- Add regression tests for normal teardown and cancelled initialization.
The teardown test waits for cancellation because the registration
callback can briefly retain `Storage` after initialization returns.

## Result

Sources are cleaned up after the last sequence or iterator releases the
storage, including when initialization is cancelled.

In the macOS reproducer, 2,000 create/drop iterations went from 2,005
live dispatch sources before the fix to 5 afterward, matching the
zero-iteration control. These measurements were made on macOS only.

All 10 UnixSignals tests pass locally in release mode on macOS with
Swift 6.3.3 and the CI warning, explicit-import, and Sendable flags.
Strict formatting and `git diff --check` also pass. The weak-reference
test has not been run locally on Linux; its first Linux validation will
be in CI.
2026-09-14 12:59:27 +00:00
Honza DvorskyandVladimir Kukushkin 44f65a61e8 [CI] Add Wasm support (#218)
## Summary

As I was trying to add Wasm CI to Swift Configuration, I noticed it
failed to build in Service Lifecycle, so adding that here first.

## Test Plan

Haven't run locally, will fail for now.

---------

Co-authored-by: Vladimir Kukushkin <kukushechkin@mac.com>
2026-03-18 15:33:36 +01:00
Franz BuschandJoannis Orlandos 1de37290c0 Enable 6.2 CI and enable Windows CI (#215)
Co-authored-by: Joannis Orlandos <joannis@orlandos.nl>
2025-11-03 19:57:02 +01:00
Franz Busch 7bef63b292 Add support for SIGPIPE (#214)
This PR adds `SIGPIPE` to the `UnixSignals`
2025-09-22 12:34:20 +02:00
George Barnett e718730918 Remove platforms from manifest (#203)
Motivation:

Adding or raising the deployment platforms in the package manifest is a
SemVer major breaking change as consumers must also add or raise their
deployment platforms. This is a known limitation of SwiftPM.

Unforunately this means that it's very difficult for non-leaf packages
to adopt packages which declare their platforms in the manifest. Doing
so puts the brakes on adoption and ecosystem growth. For 'core' packages
like this one availability constraints should be expressed on
declarations rather than in the manifest.

Modifications:

- Remove platforms from the package manifest
- Add availability annotations to types which require it

Result:

This package can be more widely adopted
2025-04-23 08:59:36 +00:00
Joannis Orlandos e2b442cc73 Import the Android module if available, since glibc and musl are unavailable on Android (#198)
I don't expect us to run CI against this until that's more formally
supported, but this would greatly help adoption of server-focused
packages on Android
2025-02-17 07:52:11 +00:00
Juri Pakaste a6a4bc71cc UnixSignal: Add SIGCONT (#192)
I'm using swift-service-lifecycle's UnixSignal in a text UI library, and
needed SIGCONT. It's probably not super relevant in the service use
case, but it looks like UnixSignal is the best way to handle signals,
service or not, and I don't know if there's a downside to the library
supporting it?
2024-12-10 10:07:22 +00:00
Franz Busch f70b838872 [CI] Adopt GitHub actions (#187)
# Motivation

We want to switch our CI to GitHub actions.

# Modification

This PR sets up the reusable workflows from NIO.

# Result

More modern CI.
2024-10-31 12:17:45 +01:00
Zack Zatkin-Gold d58e6bf2b1 add support for trapping sigabrt, sigill, sigsegv (#184)
- sigabrt: usually generated by the abort() function. Useful for cleanup prior to termination.
- sigill: issued if the user attempts to execute an illegal, malformed, or privileged instruction.
- sigsegv: issued if the user makes an invalid memory reference, such as dereferencing a null or invalid pointer.
2024-06-03 07:11:49 -07:00
Si Beaumont 12a031bcc1 Support compiling against Musl (#182) 2024-05-08 09:08:21 -07:00
Franz Busch b71a961c12 Add support for SIGWINCH (#161)
# Motivation
`SIGWINCH` is sent to applications when the window resizes. This is useful to observe for terminal applications to reformat the logging one resize.

# Modification
This PR adds support for `SIGWINCH` in `UnixSignal`s.
2023-10-10 19:31:12 +01:00
Franz Busch f58dbbfaa9 Add support for return/ThrowBehavior of services (#148)
* Add support for `return/ThrowBehavior` of services

# Motivation

Currently the `ServiceGroup` cancels the whole group when a service returns or throws. This is fine for most server applications but it doesn't work for CLI tools since they mostly want to use the group to orchestrate the services as long as the user command is handled and then return cleanly from the group. Furthermore, even on server setups one might want to customize the behavior of what happens when a service returns/throws e.g. one might want to shutdown the group after their HTTP server throws so that a telemetry service flushes out all the remaining data.

# Modification

This PR does a few things:
1. It creates a new `ServiceConfiguration` and `TerminationBehavior` in the `ServiceGroupConfiguration`. Those can be used to declare the services that are run and what happens when the service returns or throws
2. Adds a new `cancellationSignals` to to the `ServiceGroupConfiguration` which allows cancellation to trigger based on a signal
3. Makes sure that any given service is only retained as long as necessary i.e. when a service returns the group is not retaining it anymore. This allows freeing of resources as early as possible
4. Breaking: Removes the `Hashable` conformance on the configuration structs. This was wrong in the first place and something we should just avoid doing in general.

# Result
We now give the user even more control about the group's behaviors.

* Review

* Review

* Fix CI
2023-08-16 13:22:22 +01:00
Franz Busch 36f71f61d7 Add support for SIGQUIT (#146)
# Motivation
Some applications want to react to `SIGQUIT` which is similar to `SIGINT` but normally maps to a different key `C-\`.

# Modification
This PR adds support for `SIGQUIT` in the `UnixSignal`s module.

# Result
Support for `SIGQUIT`.
2023-08-14 11:18:31 +01:00
Franz Busch de1ef4ba30 Use #if canImport(Darwin) where possible (#144) 2023-06-21 14:08:40 +01:00
Franz Busch fafab8f7ad Overhaul service lifecycle for Structured Concurrency (#130)
* Overhaul service lifecycle for Structured Concurrency

# Motivation
Since the release of Swift Concurrency the server ecosystem has adopted `async`/`await` in a lot of APIs making the user experience amazing. Another thing that Swift Concurrency introduced is Structured Concurrency which allows to create a task tree that with parent to child relations. Structured Concurrency has many benefits such as automatic cancellation and task local propagation.
The current state of this library predates the introduction of Swift Concurrency and is not inline anymore with how applications are structured that want to leverage Concurrency.

# Modification
This PR overhauls the implementation of service lifecycle completely. The reason for this is that the current implementation is very focused on how NIO based applications work before the introduction of Concurrency. Furthermore, Structured Concurrency is actually replacing part of the current functionality by providing new scoping mechanisms.
The overhauled implementation provides two primitive types. Anew `Service` protocol and a `ServiceRunner`. The former is providing a clear API which services have to conform to so that they can be run by the `ServiceRunner`.

An example usage of the types looks like this

```swift
actor FooService: Service {
    func run() async throws {}

    func shutdownGracefully() async throws {}
}
actor BarService: Service {
    func run() async throws {}

    func shutdownGracefully() async throws {}
}

let fooService = FooService()
let barService = BarService()

let runner = ServiceRunner(
    services: [fooService, barService],
   configuration: .init(),
   logger: logger
)

try await runner.run()
```

# Result
We now have a service lifecycle library that integrates nicely with Structured Concurrency. Its value add is that it solves to complex setup of the task group with the signal handling. Furthermore, it provides a currency type `Service` that can be passed to inject services.

* Remove `shutdownGracefully` method and switch to a handler based approach.

* Code review from George

* Add extensions to `TaskGroup` and `ThrowingTaskGroup`

* Remove long running property

* Documentation

* Fix tests

* Ensure ordering of shutdown

* Test

# Motivation

# Modification

# Result

* Introduce ServiceLifecycleTestKit

* Add AsyncCancelOngracefulShutdownSequence

* Tests and docs for graceful shutdown

# Motivation

# Modification

# Result

* Remove unsafe flags

* Add article for application authors

* Add correct licence and notice information for the things we copied from swift-nio

* Code review

* Remove @_unsafeInheritExectuor

* Code review

* Change log levels, rename to withGracefulShutdownHandler and support nested service runner graceful shutdown

* Add public `shutdownGracefully` method to the service runner

* Code review and expose new cancelOnGracefulShutdown method

* Extend graceful shutdown APIs and tolerate running outside of a `ServiceRunner`

* Rename to `ServiceGroup`

* Enable Swift 5.6 support

* Update soundess dockerfile

* Update Readme

* Make 5.6 build work
2023-04-27 11:56:08 +01:00