Commit Graph
2731 Commits
Author SHA1 Message Date
Rick Newton-Rogers ddbb053756 formatting 2025-04-11 12:01:15 +01:00
Rick Newton-Rogers 828a1130b1 Merge branch 'main' into queue_outbound_close 2025-04-11 09:29:11 +01:00
Rick Newton-Rogers e60b390aab PendingWritesManager returns close promise 2025-04-11 09:28:57 +01:00
George BarnettandCory Benfield d0fb818d9c Strict concurrency for NIOPosixTests EchoServerClient (#3195)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-10 19:22:48 +00:00
Raghav Roy 8440498328 Add More Peek API Variants for ByteBuffer (#3174)
### Motivation:

Existing get APIs require passing an explicit index and can be misused,
leading to verbose and error-prone code. Adding peek variants that
automatically use the current readerIndex improves safety and clarity.
This aims to address issue #2034 and issue #2736, and is a continuation
of PR #3157

### Modifications:

Introduced peekSlice(), peekLengthPrefixedSlice(), peekData(),
peekUUIDBytes() and peekWebSocketErrorCode().
Added tests for each peek API covering normal, empty and repeated peek
scenarios.

### Result:

Developers can now use nonmutating peek APIs to inspect ByteBuffer
contents without altering the reader index.
2025-04-10 14:44:53 +00:00
George BarnettandCory Benfield 25394096e5 Strict concurrency for NIOPosixTests, EL and ELF (#3193)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-10 14:18:10 +00:00
Raghav RoyandCory Benfield 12d8a4c6d7 Add Peek API for Multiple Integers (#3175)
### Motivation:

The current readMultipleIntegers methods are used to consume multiple
integer values at once, but lack an equivalent nonmutating API. This can
lead to unnecessary complexity when users want to inspect values without
advancing readerIndex. THis patch introduces peekMultipleIntegers which
uses the current readerIndex, improving safety. This extends previous
work on peek methods (issue #2034, issue #2736).

### Modifications:

Updated the generation script (.sh file) to produce peekMultipleIntegers
variants for each arity of readMultipleIntegers.
    Added new tests mirroring the existing multi-read/write tests

### Result:

Users can now inspect multiple integer values in a ByteBuffer without
consuming them, enabling safer workflows.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-10 10:23:27 +00:00
George Barnett f9fd017096 Remove unchecked from SelectorTest (#3192)
Motivation:

One of the SelectorTests used an `@unchecked Sendable` box which did
runtime checking of the `EventLoop`. We have a type for this already,
it's called `NIOLoopBoundBox`, we should use it.

Modifications:

- Replace `Box` with `NIOLoopBoundBox`

Result:

Fewer `@unchecked Sendable`s
2025-04-10 10:45:20 +01:00
Rick Newton-Rogers d41ef1ba4f Merge branch 'main' into queue_outbound_close 2025-04-10 06:18:00 +01:00
George BarnettandCory Benfield 69e8d39aa4 Expose the event loop from the loop bound boxes (#3179)
Motivation:

NIOLoopBound and NIOLoopBoundBox both have a public-but-underscored
event loop property, i.e. the loop to which the value is bound. It's
often very helpful to be able to access the event loop the value is
isolated to. Having access allows you to execute onto the event loop and
safely access the value.

Modifications:

- Make the property public and add a deprecated shim for the
public-but-underscored variant.

Result:

Can access the event loop of a loop bound value

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-09 13:47:34 +00:00
George Barnett a0df65d474 Strict concurrency for NIOPosix ChannelTests (#3191) 2025-04-09 13:22:42 +00:00
Fabian FettandCory Benfield 1d1ce62c8e Add perf test for EL as SerialExecutor (#3178)
This PR adds two benchmarks:

- Jumping 1k times from the global executor to a NIO EL and back using
`el.execute {}` and an `UncheckedContinuation`
- Jumping 1k times from the global executor to a NIO EL and back using
an actor that has a custom executor

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-09 12:54:37 +00:00
George Barnett 3fd5e7484f Strict concurrency for NIOPosix StreamChannelsTest (#3189) 2025-04-09 12:08:27 +00:00
George Barnett 431b5097ae Strict concurrency for NIOPosix NonBlockingFileIOTest (#3188) 2025-04-09 11:12:22 +00:00
George BarnettandGus Cairo cee62a0354 Strict concurrency for NIOPosix SelectorTest (#3190)
Co-authored-by: Gus Cairo <me@gustavocairo.com>
2025-04-09 09:42:16 +00:00
George Barnett 18408abca3 Strict concurrency for NIOPosix ChannelPipelineTests (#3184) 2025-04-08 15:25:25 +00:00
George Barnett 06b7d4c9cc Strict concurrency for NIOPosix AcceptBackoffHandlerTests (#3182) 2025-04-08 15:00:42 +00:00
Rick Newton-Rogers 5a9130b5c2 Static SDK installation script improvements (#3186)
Static SDK installation script improvements

### Motivation:

Make static SDK installation scripts more modular and make
failures easier to diagnose.

### Modifications:

- Allow specification of binaries from outside the installation script
- Remove script dependency installation from the script
- Separate the Swift dependency installation into its own script
- Fatal error explicitly if the installed Swift can't be found
- Make curl operations for downloading artifacts explicitly fail

### Result:

Scripts which are easier to maintain and operate.

An example CI run with this in operation
https://github.com/apple/swift-nio/actions/runs/14329482180/job/40162003318?pr=3186
2025-04-08 14:27:30 +00:00
George Barnett 83441a3bb3 Strict concurrency NIOPosix EventLoopTest (#3185) 2025-04-08 13:49:14 +00:00
George Barnett f35421bd63 Strict concurrency for NIOPosix BootstrapTest (#3183) 2025-04-08 13:20:43 +00:00
Marc Prud'hommeaux c626de9f4d Ignore return value of signal() on Android (#3181)
Fixes https://github.com/apple/swift-nio/issues/3180 by ignoring return
value of signal() on Android
2025-04-08 12:52:04 +00:00
Rick Newton-Rogers 8a475ed378 Update nightly main benchmark thresholds (#3187)
### Motivation:

Nightly main benchmarks have improved allocations, we should lock in the
win.

### Modifications:

Update nightly main benchmark thresholds

### Result:

Thresholds reflect gains, passing CI.
2025-04-08 11:20:14 +01:00
George Barnett 4b7854daaa Strict concurrency for NIOPerformanceTester and NIOCrashTester (#3167) 2025-04-07 14:10:48 +00:00
George BarnettandRick Newton-Rogers 202f987738 Strict concurrency for NIOHTTP1Tests (#3169)
Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-04-07 11:27:05 +01:00
Rick Newton-Rogers 350794f229 uncomment visionOS CI tasks (#3176)
### Motivation:

These don't work on all versions but we should allow people to opt-in if
they know they do work

### Modifications:

Uncomment the steps and make the step default to off

### Result:

People can choose to run visionOS builds and tests
2025-04-04 14:01:18 +01:00
Gus Cairo 7d3204d232 Improve alloc tests failure messages (#3173)
This PR improves the messaging when tests fail so it's easier to
troubleshoot failures.
2025-04-03 15:23:41 +00:00
Rick Newton-Rogers b3704d764b Add support for Xcode 16.3 (#3171)
### Motivation:

Xcode 16.3 has been released, we should cover it in CI

### Modifications:

* Add Xcode 16.3 runs by default
* Disable Xcode 16.0 runs by default (soft deprecation)

Note that the Xcode version offering is still a work in progress.

### Result:

macOS CI will test using Xcode 16.3

An example run with this working
https://github.com/apple/swift-nio/actions/runs/14220724296/job/39876502770?pr=3171
2025-04-03 10:32:50 +01:00
Rick Newton-Rogers 92fa8204c4 Merge branch 'main' into queue_outbound_close 2025-04-02 13:58:53 +01:00
Rick Newton-Rogers e4395376d6 review comments 2025-04-02 10:23:48 +01:00
George Barnett 0270310d75 Document supported versions consistently (#3168)
Motivation:

The README mentions indicates the supported Swift versions in a few
places which over time have gotten out of sync.

Modifications:

- Only document the supported Swift version in the 'supported versions'
section of the README

Result:

- Resolves #3158
2025-04-02 07:22:23 +00:00
George Barnett 195bca151e Strict concurrency for websocket client/server demo and async demo (#3161) 2025-04-01 16:39:33 +00:00
Rick Newton-Rogers b4451dc7b9 Update install_static_sdk.sh to cope with versions with no patch (#3166)
Update install_static_sdk.sh to cope with versions with no patch. The
existing `sed` regex assumed `major.minor.patch`
2025-04-01 17:08:04 +01:00
Rick Newton-Rogers be80eb6e5d macOS CI pools (#3163)
Add support for macOS CI runner pools

### Motivation:

With new runners coming online we are separating the runners into pools.
* "nightly" runners are to be targeted for asynchronous work which users
aren't waiting on such as overnight work.
* "general" runners can be used for either synchronoous or asynchronous
work.
* At the moment all runers are "general" runners, a subset are "nightly"
runners.

The aim here is to prioritize work which users are waiting for such as
on PRs. Asynchronous work prioritizing the "nightly" runners will likely
end up queuing for the contended runners but synchronous work will claim
any available node.

### Modifications:

* Add a `runner_pool` input for the macOS workflow
* Default the `runner_pool` to `nightly` since the vast majority of
existing workflows are specifying asynchronous work.
* Specify the runner pool in NIO's use of macOS CI.

### Result:

Support for runner pools.

An example of this in action:
https://github.com/apple/swift-nio/actions/runs/14188573697/job/39748250001
2025-04-01 10:35:17 +02:00
Rick Newton-Rogers 32b232af17 review comments 2025-03-31 15:33:24 +01:00
Rick Newton-Rogers 081a205669 Merge branch 'main' into queue_outbound_close 2025-03-31 15:30:26 +01:00
Rick Newton-Rogers 1f0cf18b12 formatting 2025-03-31 15:30:15 +01:00
Rick Newton-Rogers 213cc0b894 Separate build and test steps in macos_tests.yml (#3162)
Separate build and test steps in `macos_tests.yml`. Test execution can
now also be disabled through an input. This is useful for clarity of
output and also in some cases where test execution may not be supported
yet.
2025-03-31 14:19:42 +00:00
Rick Newton-Rogers 68397e0455 review comments 2025-03-31 13:53:20 +01:00
Raghav Roy 1d7a94655f Add Peek API variants for ByteBuffer (#3160)
### Motivation:
Existing get APIs require passing an explicit index and can be misused,
leading to verbose and error-prone code. Adding peek variants that
automatically use the current readerIndex improves safety and clarity.
This aims to address https://github.com/apple/swift-nio/issues/2034 and
https://github.com/apple/swift-nio/issues/2736, and is a continuation of
PR https://github.com/apple/swift-nio/pull/3157

### Modifications:
- Introduced peekBytes(), peekString(), peekNullTerminatedString(),
peekUTF8ValidatedString() and peekDispatchData().
- Added tests for each peek API covering normal, empty, repeated, and
partial read scenarios.

### Result:
Developers can now use nonmutating peek APIs to inspect ByteBuffer
contents without altering the reader index.

***PS**: I have focussed on the ByteBuffer-aux get\* implementations, so
I'm not sure if I am missing any other important/error-prone get\*
elsewhere, if so, please point me to them and I'll be happy to add
respective peek\*'s!*
2025-03-31 10:30:37 +01:00
George Barnett 825d963ea1 Use overflow addition in tests to avoid compilation failures (#3155)
Motivation:

A few tests are failing to compiler on 32-bit platforms with recently
nightly toolchains. These tests are skipped if `Int` is 32 bits wide but
the compiler doesn't know that.

Modifications:

- Use overflow addition to stop the compiler from complaining; the
addition won't ever actually overflow because of the runtime check done
ahead of time.

Result:

- Tests compile again
- Resolves #3154
2025-03-27 11:31:36 +00:00
Raghav RoyandGeorge Barnett e8260eb721 Add peekInteger API to ByteBuffer (#3157)
### Motivation:

The existing getInteger API is often used incorrectly, leading to
verbose or error-prone code as mentioned in
https://github.com/apple/swift-nio/issues/2034 and
https://github.com/apple/swift-nio/issues/2736. Users may
unintentionally access data without correctly managing the reader index.
To address this, I added a peekInteger API that reads integers using the
current readerIndex without modifying it.

### Modifications:

* Added a peekInteger method to ByteBuffer, which provides a nonmutating
way to read integers using the current readerIndex.
* Implemented peekInteger using the existing getInteger function.
* Added comprehensive unit tests to validate correct behavior, including
scenarios for different integer types, insufficient bytes, and
multi-write scenarios.

### Result:

* Users now have access to a safer API for inspecting integers in a
buffer without modifying state.
* Added tests for integer reading scenarios.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-03-27 09:54:07 +00:00
scottmarchantandScott Marchant 320fe4c406 fix: Fix NIOCore build for wasm targets (#3156)
Fixes NIOCore compiler errors for the `wasm32` architecture.

### Motivation:

When compiling NIOCore for a SwiftWasm target, several compilation
errors such as the following occur:

```
> swift build --swift-sdk wasm32-unknown-wasi --target NIOCore

.../swift-nio/Sources/NIOCore/FileHandle.swift:151:42: error: cannot find type 'TwoUInt32s' in scope
149 | public final class NIOFileHandle: FileDescriptor & Sendable {
150 |     private static let descriptorClosed: CInt = CInt.min
151 |     private let descriptor: UnsafeAtomic<TwoUInt32s>
    |                                          `- error: cannot find type 'TwoUInt32s' in scope
152 | 
153 |     public var isOpen: Bool {
.../swift-nio/Sources/NIOCore/FileHandle.swift:77:8: error: Unknown architecture
 75 | typealias TwoUInt32s = DoubleWord
 76 | #else
 77 | #error("Unknown architecture")
    |        `- error: Unknown architecture
 78 | #endif
 79 | 
 
…
```
The compilation errors were introduced with the following change: 


https://github.com/apple/swift-nio/pull/2598/files#diff-a041d0c0d50a8f4fcda2020eeb4450ea994920ef61653cc06014457ccdb3ba0cR70

### Modifications:

The fix is straight-forward and unlikely to affect any existing
compilation targets other than the `wasm32` target.

We simply need to add `arch(wasm32)` to compiler architecture condtions
for a new typedef on line, then NIOCore compiles to wasm32 again.

### Result:

Before: NIOCore wasm build fails ❌ 

After: NIOCore wasm build succeeds ✅

Co-authored-by: Scott Marchant <scottm@passivelogic.com>
2025-03-27 09:28:30 +00:00
Rafael CepedaandFranz Busch 050158c75a Changed NIOAsyncChannel.executeThenClose to accept actor-isolated parameter (#3121)
Improve usability of NIOAsyncChannel.executeThenClose function from an
Actor

### Motivation:

When calling executeThenClose from inside an actor, the closure which we
pass is not isolated to the same actor
This makes it hard to use

e.g. the following code won’t compile on Swift 6 because the closure is
`self-isolated` so can’t be passed

```
await withDiscardingTaskGroup { group in
            do {
                try await serverChannel.executeThenClose { inboundStream, _ in
                    try await self.handleInboundStream(inboundStream: inboundStream, group: &group)
                }
             } catch {}
}
```

Making the closure as @Sendable allows it to be passed, but then we
can’t access `group` anymore

### Modifications:

Added actor isolation parameter to the `executeThenClose` function. 

### Result:

`executeThenClose` will be able to be asynchronously called from inside
an Actor, as it will now be part of the Actor's isolation domain.

---------

Co-authored-by: Franz Busch <privat@franz-busch.de>
2025-03-25 13:31:39 +00:00
Rick Newton-Rogers 771810f5f8 A script for updating benchmark thresholds from CI output (#3151)
### Motivation:

We have GitHub Actions CI running Swift Package Benchmark benchmarks on
each commit but when the values don't match updating them can be time
consuming. Particularly because you need to may need to exactly match
the running environment in CI to get matching numbers.

### Modifications:

Added a new dev script which pulls the output for the benchmark GitHub
actions runs on a PR and updates your local threshold files

### Result:

Easier benchmark threshold updates

Example interaction (actually on my branch of NIO SSL where I've messed
with the thresholds so they need an update):
```
❯ FETCH_PR_URL=https://github.com/rnro/swift-nio-ssl/pull/5 OUTPUT_DIRECTORY=Benchmarks/Thresholds/ ../swift-nio/dev/thresholds-from-benchmark-output.sh
** Updating: Benchmarks/Thresholds//nightly-main/NIOSSHBenchmarks.SimpleHandshake.p90.json job:39048331461
** Nothing to update: rnro/swift-nio-ssl 5.10 job:39048331486
** Nothing to update: rnro/swift-nio-ssl 5.9 job:39048331454
** Nothing to update: rnro/swift-nio-ssl 6.0 job:39048331469
** Nothing to update: rnro/swift-nio-ssl nightly-next job:39048331466
2025-03-21 16:17:14 +00:00
Johannes Weiss 40ee44c6b9 always @preconcurrency import Glibc/Musl/Android/Bionic/WASILibc (#3153)
### Motivation:

The non-`Darwin` libcs don't have the correct concurrency annotations.
But due to these Swift bugs, it's important that the _first_ importer
uses `@preconcurrency`:

- https://github.com/swiftlang/swift/issues/79414
- https://github.com/swiftlang/swift/issues/77866

### Modifications:

Much like the Foundation (& corelibs) PRs such as
https://github.com/swiftlang/swift-foundation/pull/1175 , use
`@preconcurrency import` for the non-`Darwin` libcs.

### Result:

Fewer bad warnings/errors in user code.
2025-03-21 15:35:05 +00:00
Rick Newton-Rogers 0e6ee4025e Merge branch 'main' into queue_outbound_close 2025-03-21 15:29:36 +00:00
Rick Newton-Rogers 716fc4767b formatting 2025-03-21 15:27:48 +00:00
Rick Newton-Rogers f762b29df4 DatagramWritesManager only supports full closure 2025-03-21 13:34:28 +00:00
Rick Newton-Rogers 2603614439 reverting unrelated changes 2025-03-21 11:22:45 +00:00
Rick Newton-Rogers 94f957387a use state machine instead of promise 2025-03-21 10:57:14 +00:00