Skip to content

NIOAsyncTestingChannel local/remote addrs on EmbeddedChannelCore#3442

Merged
rnro merged 6 commits intoapple:mainfrom
rnro:asynctestingchannel_socketaddress
Nov 11, 2025
Merged

NIOAsyncTestingChannel local/remote addrs on EmbeddedChannelCore#3442
rnro merged 6 commits intoapple:mainfrom
rnro:asynctestingchannel_socketaddress

Conversation

@rnro
Copy link
Copy Markdown
Contributor

@rnro rnro commented Nov 10, 2025

Motivation:

NIOAsyncTestingChannel stored its localAddress and remoteAddress in a locked storage on itself for thread safety, however in doing so left us open to bugs because a handler grabbing the addresses of the context had no visibility of the values.

Modifications:

Reach into EmbeddedChannelCore for the addresses instead of storing them on the NIOAsyncTestinghannel. I also considered a delegate approach where the EmbeddedChannelCore could offload the responsibility for storing the values back to the
NIOAsyncTestingChannel but it was complicated and of questionable value.

Result:

  • The correct address values are seen no matter how they are obtained.
  • We probably take a performance hit locking the values in this way but this is testing code so probably not the end of the world.

@rnro rnro changed the title NIOAsyncTestingChannel local/remote addrs on EmeddedChannelCore NIOAsyncTestingChannel local/remote addrs on EmbeddedChannelCore Nov 10, 2025
@rnro rnro added the 🔨 semver/patch No public API change. label Nov 10, 2025
@rnro rnro force-pushed the asynctestingchannel_socketaddress branch from e3f4abb to 58857be Compare November 10, 2025 15:14
@rnro rnro marked this pull request as ready for review November 10, 2025 15:47
Comment on lines +509 to +522
internal let _localAddress: NIOLockedValueBox<SocketAddress?> = NIOLockedValueBox(nil)

@usableFromInline
var remoteAddress: SocketAddress?
var localAddress: SocketAddress? {
get {
self._localAddress.withLockedValue { $0 }
}
set {
self._localAddress.withLockedValue { $0 = newValue }
}
}

@usableFromInline
internal let _remoteAddress: NIOLockedValueBox<SocketAddress?> = NIOLockedValueBox(nil)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we have these share a NIOLockedValueBox? No real sense in having the extra allocations here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep, sure. I considered using a tuple but decided to go for a single-use struct instead to reduce the risk for confusion of the two SocketAddresses

Lukasa added a commit that referenced this pull request Nov 10, 2025
### Motivation:

We have a way to update Benchmarks thresholds from CI logs but not for
the older Integration Tests.

### Modifications:

A new script which pulls integration test logs and uses our existing
parsing script to pull out updated values.

### Result:

Easier threshold updates.


```
❯ ./dev/update-integration-test-thresholds.sh
Usage: ./dev/update-integration-test-thresholds.sh <url>
   or: URL=<url> ./dev/update-integration-test-thresholds.sh

Example:
  ./dev/update-integration-test-thresholds.sh #3442
  ./dev/update-integration-test-thresholds.sh https://github.com/apple/swift-nio/actions/runs/19234929677
  URL=#3442 ./dev/update-integration-test-thresholds.sh
```

```
❯ ./dev/update-integration-test-thresholds.sh 'https://github.com/apple/swift-nio/actions/runs/19234929677/job/54982236271?pr=3442'
** Processing run in apple/swift-nio
** Fetching integration test checks from workflow run 19234929677
** Pulling logs for Swift nightly-main (job 54982236243)
** Updated IntegrationTests/tests_04_performance/Thresholds/nightly-main.json
** Pulling logs for Swift 6.2 (job 54982236259)
** Updated IntegrationTests/tests_04_performance/Thresholds/6.2.json
** Pulling logs for Swift nightly-next (job 54982236267)
** Updated IntegrationTests/tests_04_performance/Thresholds/nightly-next.json
** Pulling logs for Swift 6.0 (job 54982236271)
** Updated IntegrationTests/tests_04_performance/Thresholds/6.0.json
** Pulling logs for Swift 6.1 (job 54982236345)
** Updated IntegrationTests/tests_04_performance/Thresholds/6.1.json
** Done! Updated 5 threshold file(s)
```

Co-authored-by: Cory Benfield <lukasa@apple.com>
rnro added 4 commits November 11, 2025 08:18
Motivation:

`NIOAsyncTestingChannel` stored its `localAddress` and `remoteAddress`
in a locked storage on itself for thread safety, however in doing so
left us open to bugs because a handler grabbing the addresses of the
context had no visibility of the values.

Modifications:

Reach into `EmbeddedChannelCore` for the addresses instead of storing
them on the `NIOAsyncTestinghannel`. I also considered a delegate
approach where the `EmbeddedChannelCore` could offload the
responsibility for storing the values back to the
`NIOAsyncTestingChannel` but it was complicated and of questionable
value.

Result:

* The correct address values are seen no matter how they are obtained.
* We probably take a performance hit locking the values in this way but
  this is testing code so probably not the end of the world.
@rnro rnro force-pushed the asynctestingchannel_socketaddress branch from 3ed8e84 to edd1a40 Compare November 11, 2025 08:27
@rnro rnro requested a review from glbrntt November 11, 2025 08:54
@rnro rnro merged commit 56724a2 into apple:main Nov 11, 2025
54 checks passed
@rnro rnro deleted the asynctestingchannel_socketaddress branch November 11, 2025 15:08
aryan-25 added a commit to aryan-25/swift-nio-http2 that referenced this pull request Feb 9, 2026
Motivation:

The nightly CI checks for Integration Tests started failing since run https://github.com/apple/swift-nio-http2/actions/runs/19310336168/job/55228659542 (on 12 November 2025).

The reason for the failures is due to the `test_client_server_h1_request_response` requiring 282,000 allocations, exceeding the threshold boundary which is currently set to 280,050 across all versions.

The date the allocations started to exceed the boundary coincides with [release 2.89.0 of swift-nio](https://github.com/apple/swift-nio/releases/tag/2.89.0). In particular, that test uses `EmbeddedChannel`, and `EmbeddedChannel` was changed in [a PR contained in that release](apple/swift-nio#3442), that introduced some changes leading to greater allocations.

[Another change to `EmbeddedChannel`](apple/swift-nio#3495) in `swift-nio`'s latest release ([2.94.0](https://github.com/apple/swift-nio/releases)) has increased the number of allocations of the `client_server_h1_request_response` test to 284,000.

We should update the allocation thresholds for that test accordingly.

Modifications:

Updated the allocation threshold for `client_server_h1_request_response` to 284,000 across all versions.

Result:

Integration tests should no longer fail.
aryan-25 added a commit to apple/swift-nio-http2 that referenced this pull request Feb 9, 2026
Motivation:

The nightly CI checks for Integration Tests started failing since run
https://github.com/apple/swift-nio-http2/actions/runs/19310336168/job/55228659542
(on 12 November 2025) due to multiple allocation benchmark tests
exceeding their allocation thresholds.

The date these failures started coincides with [release 2.89.0 of
`swift-nio`](https://github.com/apple/swift-nio/releases/tag/2.89.0). In
particular, all failing allocation benchmarks use `EmbeddedChannel`, and
`EmbeddedChannel` was changed in [a PR contained in that
release](apple/swift-nio#3442) that introduced
some changes leading to greater allocations.

[Another change to
`EmbeddedChannel`](apple/swift-nio#3495) in
`swift-nio`'s latest release
([2.94.0](https://github.com/apple/swift-nio/releases)) has also
increased the number of allocations in benchmarks using
`EmbeddedChannel`.

As such, we should update the allocation thresholds for affected tests
accordingly.

Modifications:

Updated the allocation threshold for all affected tests across all
versions.

Result:

Integration tests should no longer fail.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants