Files
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
..