Commit Graph
2945 Commits
Author SHA1 Message Date
Rick Newton-Rogers d8b0dbeb4d Enable visionOS xcodebuilds by default in CI - attempt 2 (#3238)
### Motivation:

Building for visionOS no longer seems to be having issues on the
runners, we should enable it to increase our test coverage.

### Modifications:

Enable visionOS xcodebuilds by default in CI

### Result:

NIO and downstream repositories will see their *existing* macOS CI
workflows now build for visionOS.

They can be disabled if necessary by passing
`visionos_xcode_build_enabled: false`


See apple/swift-nio#3234, apple/swift-nio#3235
2025-05-13 14:01:50 +00:00
Rick Newton-Rogers d53225264f Update check-matrix-job.sh to default swift commands (#3237)
Update check-matrix-job.sh to default swift commands so that callers
which don't define them can still run workflows. At the moment they see
failures if they don't define any one of the commands.
2025-05-13 11:31:54 +00:00
Rick Newton-Rogers 7ed5a41281 Macos setup command (#3236)
Add per-xcode setup command

###  Motivation:

Sometimes individual Xcodes require different steps to fixup simulator
configuration.

### Modifications:

* Allow the config to define custom setup steps
* Add some `simctl` commands to Xcode 16.2 by default to workaround
issues

### Result:

Adopters can specify their own setup steps

Example of this working with a test shim in place
https://github.com/apple/swift-nio/actions/runs/14992683747/job/42119567309?pr=3236
2025-05-13 11:12:35 +01:00
a0c542bff1 Fix NIOAsyncWriter test on concurrency thread pool with single thread (#3135)
### Motivation:

The testSuspendingBufferedYield_whenWriterFinished test fails on the
Android emulator. See also the discussion in #3044.

### Modifications:

The test requires at least two threads in the concurrency thread pool
because it blocks one task, which waits for another task to set a
condition. This PR adds support for running a task executor based on a
NIOThreadPool and uses it for the test. Using a custom task executor
guarantees that at least two threads are available for the test.

Additionally, the test has been renamed to
testWriterFinish_AndSuspendBufferedYield, which is more in line with the
other test names.

### Result:

The test will pass regardless of the width of the global concurrency
thread pool.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-05-12 15:12:53 +01:00
Rick Newton-Rogers 34d486b01c Revert "Enable visionOS xcodebuilds by default in CI" (#3235)
Reverts apple/swift-nio#3234

This seems to have caused some instability which I'll investigate so we
should revert for now.
2.83.0
2025-05-09 14:40:35 +01:00
Rick Newton-Rogers 00fedd68f4 Enable visionOS xcodebuilds by default in CI (#3234)
### Motivation:

Building for visionOS no longer seems to be having issues on the
runners, we should enable it to increase our test coverage.

###Modifications:

Enable visionOS xcodebuilds by default in CI

### Result:

NIO and downstream repositories will see their *existing* macOS CI
workflows now build for visionOS.

They can be disabled if necessary by passing
`visionos_xcode_build_enabled: false`
2025-05-08 10:26:40 +01:00
Rick Newton-Rogers c78bc87f8f Disable Swift 5.9 CI jobs by default (#3233)
### Motivation:

Swift 5.9 is no longer supported and CI has been updated to no longer
require it, we should disable it by default.

### Modifications:

* Default Swift 5.9 CI jobs to disabled

### Result:

Swift 5.9 CI jobs will not run unless opted-in
2025-05-08 08:37:40 +01:00
Rick Newton-Rogers 8b74598216 Remove assertions on PWM failAll and closeOutbound (#3231)
### Motivation:

`failAll` and `closeOutbound` are likely to be called multiple times,
either because of the user calling close or because the channel reads
EOF.

Depending on the ordering it is possible with the recent code changes
for us to reach code which currently asserts we are open when a prior
close operation has set `isOpen` to false.

Before the recent change which queues outbound closes behind pending
writes was made an outbound mode close after reading EOF would result in
an error (file descriptor already closed!: Bad file descriptor), after
the change was made it would cause an assertion failure.

### Modifications:

* Remove the assertions for `isOpen` in `failAll` and `closeOutbound`,
we can tolerate being called more than once.
* Issue socket shutdown even if we believe we are closed to match
previous behavior and the behavior of the other SocketChannels
* Update the `isOpen` state in `closeOutbound`, this was missing.
* Add a test which panics before this change.

### Result:

The code is more tolerant of multiple close operations and the previous
behavior is restored
2025-05-07 19:40:13 +01:00
Rick Newton-Rogers 14dcafc6ec Update Array+FileSystem.swift to add visionOS (#3220)
Fix visionOS builds and tests

### Motivation:

visionOS builds and tests were failing because of missing cases in
availability guards.

### Modifications:

Spell guards in terms of Darwin where appropriate, add visionOS

### Result:

Example run of this working in CI
https://github.com/apple/swift-nio/actions/runs/14876166161/job/41773757638?pr=3220
2025-05-07 13:22:23 +00:00
Rafael CepedaandGeorge Barnett afa7d4f57d Moving PooledRecvBufferAllocator from NIOPosix to NIOCore (#3110)
Moving `PooledRecvBufferAllocator` from NIOPosix to NIOCore, making it
part of its public interface.

### Motivation:

We want to introduce the capability of reusing receiving buffers from a
pool into swift-nio-transport-services project. To prevent duplicating
this functionality there, this change is making the existing
functionality from NIO part of its public API.

### Modifications:

Moved the type `PooledRecvBufferAllocator` from NIOPosix module to
NIOCore and turned it into a public type.

### Result:

`PooledRecvBufferAllocator` is part of NIOCore public API.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-05-07 12:50:15 +00:00
Rick Newton-Rogers 57658e12ff Drop Swift 5.9 (#3228)
Motivation:

Swift 5.9 is no longer supported, we should bump the tools version and
remove it from our CI.

Modifications:

* Bump the Swift tools version to Swift 5.10
* Remove Swift 5.9 jobs where appropriate in main.yml, pull_request.yml

Result:

Code reflects our support window.
2025-05-07 12:24:44 +00:00
Axel AnderssonandGeorge Barnett 960dcfb29b Make ChannelError and NIOConnectionError conform to CustomStringConvertible (#3230)
### Motivation:

`ChannelError` and `NIOConnectionError` should conform
`CustomStringConvertible` so that these errors can be easily logged.

As discussed in https://github.com/apple/swift-nio/issues/3222.

### Modifications:

Added conformance to `ChannelError` and wrote error messages for all
cases.

Added conformance to `NIOConnectionError`.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2025-05-07 10:40:46 +00:00
Rick Newton-Rogers 952b72bba9 Update SECURITY.md (#3232)
### Motivation:

To give up-to-date guidance on submitting security vulnerabilities.

### Modifications:

Updated the Disclosures section of SECURITY.md

### Result:

More accurate guidance on submitting information on security
vulnerabilities.
2025-05-07 08:35:03 +01:00
Jaleel AkbashevandRick Newton-Rogers bdbabb2827 Removed Docker references as repo moved to Github actions (#3227)
### Motivation:

A bit confusing to see docker mentioned in Readme file, when in reality
you can't run docker compose anymore.

### Modifications:

Updated README and CONTRIBUTING files, removed some scripts.

### Result:

No mentions of docker so users are not confused.

Co-authored-by: Rick Newton-Rogers <rnro@apple.com>
2025-05-05 12:08:27 +01:00
Cory Benfield abe4f1bcb6 Replace almost all public static lets with computed vars (#3229)
Motivation:

Public static lets can serve a bunch of roles, but one of them is to
store simple constants: integers, and other trivial types, for example.
This is a nice pattern and for internal and private static lets it works
well, but for public ones it produces some inefficient code.

In particular, it has two downsides. First, it allocates storage for
that value. We don't actually need to allocate a few hundred extra
megabytes for the various integers we want to store.

Secondly, it forces calling code to access the address and call the
dispatch_once code in order to get hold of the value. For trivial types
we don't need that cost: they can just know what the value is directly.

Inlinable computed vars avoid all of these costs: they have no size
overhead for storage, and they are visible to all clients so their
values can be directly assembled.

While I'm here, I added a bunch of other inlinable annotations for a few
trivial data types I stumbled onto.

Modifications:

- Added loads of inlinables. Like, loads.
- Swapped many static lets to static vars.

Result:

Better codegen, smaller memory footprints, more attributes.
2025-05-02 16:08:10 +01:00
Rick Newton-Rogers ea8703616e BaseStreamSocketChannel half-close allows outstanding writes to complete (#3148)
### Motivation:

At the moment half-closes are actioned immediately and fails all
outstanding writes. We should refuse new writes but allow these writes
to complete before completing the close.

### Modifications:

Modify the PendingWritesManager internal buffer to hold an enum of
either writes or close events. We use this to store the close and only
action it when the preceding writes have been handled.

### Result:

Outbound close should no longer fail outstanding writes

Should resolve https://github.com/apple/swift-nio/issues/3139
2025-04-30 14:56:03 +01:00
Cory Benfield 0f54d58bb5 Fix compiler issues on 5.10 x86 Ubuntu Noble. (#3224)
Motivation:

There's a known compiler issue on the 5.10 toolchain for x86 on Ubuntu
Noble. This issue causes the compile to fail, even though the code is
fine. We shouldn't allow that.

Modifications:

Shuffle the whitespace around to fix the issue.
Suppress the linter issues.

Result:

Compiler is back. Resolves #3223.
2.82.1
2025-04-28 10:07:35 +00:00
Cory BenfieldandGeorge Barnett 6e17bc9468 Update LLHTTP and apply patch to support C++ interop (#3216)
### Motivation

C++ interop support in Xcode has started to dislike the header files
from llhttp. While a bug has been filed upstream at
https://github.com/nodejs/llparse/issues/71 it doesn't seem as though
there is any movement on that fix upstream. As a result, we need to
apply a patch.

To keep the code maintainable, we'd like to apply that patch in an
automated fashion, so we should do so by amending the "update and patch"
script. Along the way, we should update LLHTTP to the latest code.

### Modifications

The modifications are split into separate commits.

1. Modify the script to fix some bugs that have crept in.
2. Run the script to update LLHTTP to latest, without the patch.
3. Fix up the tests to account for the fact that we get some different
errors from LLHTTP now.
4. Apply the patch suggested by @postmechanical in #3093
5. Re-run the script, which only applies the patch

### Result

C++ interop should be working again. Resolves #3093.

---------

Co-authored-by: George Barnett <gbarnett@apple.com>
2.82.0
2025-04-22 13:11:47 +01:00
Tony Allevato 6615a44917 Fix ByteBufferTests when compiling with Swift 6 but running on macOS 14. (#3217)
Writing `@available(someOS...)` on an XCTest test method only affects
whether the compiler allows known-available APIs to be called, but it
doesn't actually prevent the test from running on older OSes (XCTest
doesn't see the annotation since it's not part of the Objective-C
runtime metadata). So if this code is compiled with Swift 6 but run on
an older OS, it will segfault when it tries to call an API that doesn't
exist on that platform.

These tests need to use an `#available` guard instead to make the
decision to skip them at runtime.
2025-04-22 08:43:06 +00:00
Cory Benfield 6789c58fdb Clarify test server error code (#3212)
Motivation

The NIOHTTP1TestServer had a weird codepath where we could hit errors
configuring the channel pipeline, but we weren't sure why. I've
investigated, and this happens because a Channel that had been accepted
earlier was closed while we were waiting to start handling it. This is
totally benign: the code works just fine in that situation.

To be clear, though, let's document the behaviour and add a test.

Modifications

- Code comment to explain the behaviour
- Added a regression test

Result

More confidence.
2025-04-16 16:02:32 +00:00
Adam FowlerandCory Benfield d7a8ff6e36 Add errorCaught to NIOTypedHTTPClientUpgradeHandler (#3210)
To handle errors fired by previous ChannelHandlers. eg
NIOSSLClientHandler

### Motivation:

Otherwise if a ChannelHandler previous to the upgrade ChannelHandler
fails the error returned is `inappropriateOperationForState` and the
error fired by the original ChannelHandler is lost.

Added `testReturnsErrorsFromPriorChannelHandlers`. Also had to
reorganise `setUpClientChannel` slightly so I could get the result of
the upgrade.

---------

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-16 14:24:42 +00:00
George Barnett c420f0d4e6 Enable strict concurrency for NIOPosixTests (#3211) 2025-04-16 13:00:13 +00:00
George BarnettandCory Benfield ae60dc3e07 Strict concurrency for SAL tests (#3205)
Motivation:

The syscall abstraction layer tests aren't sendable clean.

Modifications:

- Factor out the setup/teardown of SAL tests into a SALContext
- SALContext a method to run a SAL test with two closues: one on the
hooked event loop and another on the calling thread.
- The EL bound closure is provided with the EL and locked boxes for the
user ot kernel and kernel to user boxes.
- The closure on the calling thread is provided with an 'assertions'
object which provides a view over the hooked selector.
- Note that there are still sendable holes in this code.
- Refactored the tests to use these APIs.

Results:

Safer tests.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-16 10:41:32 +00:00
George BarnettandCory Benfield 81375efead Strict concurrency for NIOTLSTests (#3207)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-16 11:12:57 +01:00
George BarnettandCory Benfield 27a1897914 Strict concurrency for NIOTestUtilsTests (#3206)
Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-15 16:03:08 +00:00
George Barnett b34052b28b Swift concurrency for NIOWebSocketTests (#3208) 2025-04-15 16:38:21 +01:00
George Barnett b7d4e5b050 Strict concurrency for a handful more NIOPosixTests (#3199) 2025-04-14 11:42:56 +00:00
Raghav RoyandCory Benfield ceb91082fe Add Tests for WebSocketErrorCode Get, Read and Write APIs in ByteBuffer (#3198)
### Motivation

The `write(webSocketErrorCode:)`, `readWebSocketErrorCode()`, and
`getWebSocketErrorCode(at:)` methods in ByteBuffer were not covered by
unit tests
https://github.com/apple/swift-nio/pull/3174#pullrequestreview-2743588010.
Since a peekWebSocketErrorCode() method was recently added, I figured I
should verify both the new peek API and the existing WebSocket error
code APIs behave correctly.

### Modifications

    Added tests for:

        write(webSocketErrorCode:)

        getWebSocketErrorCode(at:)

        readWebSocketErrorCode()

    Tests verify:

        Correct encoding and decoding of WebSocket error codes

        Reader index behavior (no movement for get, movement for read)

        Handling of insufficient bytes

        Consistency between peek-before-read and post-read

### Result
These tests ensure the WebSocket error code APIs in ByteBuffer are
correct, and safe to use.

Co-authored-by: Cory Benfield <lukasa@apple.com>
2025-04-14 10:52:25 +00:00
Rick Newton-Rogers c5cc43d1df Update matrix job script for 6.1 (#3201)
### Motivation:

The matrix job script used by the legacy Swift matrix workflow is still
used directly in some places where they need to run sidecar services, it
hasn't been updated for Swift 6.1

### Modifications:

Add cases for Swift 6.1 and clean up some missed changes for the
nightly-6.1 -> nightly-next naming change.

### Result:

Downstream services should be able to run matrix workflows with Swift
6.1.
2025-04-14 10:20:46 +00:00
Rick Newton-Rogers b8c446368d Add and enable Swift 6.1 workflows (#3196)
Add and enable Swift 6.1 workflows

### Motivation:

Swift 6.1 has been released, we should add it to our CI coverage.

### Modifications:

* Update `appe/swift-nio/scripts/generate_matrix.sh`
* Update reusable adopters of `swift_test_matrix.yml`
* Update end-user adopter workflows of `swift_test_matrix.yml`
  * Copy over test flags from Swift 6.0 jobs

### Result:

NIO tests against Swift 6.1 in CI and downstream repositories can
opt-in.

(Successful CI run with the workflows modified to use the changes on
this branch
https://github.com/apple/swift-nio/actions/runs/14400598096?pr=3196)
2025-04-11 13:45:49 +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
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