NIOAsyncTestingChannel local/remote addrs on EmbeddedChannelCore#3442
Merged
rnro merged 6 commits intoapple:mainfrom Nov 11, 2025
Merged
NIOAsyncTestingChannel local/remote addrs on EmbeddedChannelCore#3442rnro merged 6 commits intoapple:mainfrom
rnro merged 6 commits intoapple:mainfrom
Conversation
e3f4abb to
58857be
Compare
glbrntt
reviewed
Nov 10, 2025
Sources/NIOEmbedded/Embedded.swift
Outdated
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) |
Contributor
There was a problem hiding this comment.
Can we have these share a NIOLockedValueBox? No real sense in having the extra allocations here.
Contributor
Author
There was a problem hiding this comment.
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>
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.
3ed8e84 to
edd1a40
Compare
glbrntt
approved these changes
Nov 11, 2025
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Motivation:
NIOAsyncTestingChannelstored itslocalAddressandremoteAddressin 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
EmbeddedChannelCorefor the addresses instead of storing them on theNIOAsyncTestinghannel. I also considered a delegate approach where theEmbeddedChannelCorecould offload the responsibility for storing the values back to theNIOAsyncTestingChannelbut it was complicated and of questionable value.Result: