Skip to content

Add API to enable throwing in EmbeddedChannel.getOption and .setOption if channel is closed#3495

Merged
simonjbeaumont merged 3 commits intoapple:mainfrom
simonjbeaumont:sb/embedded-opt-in-throwing-options
Jan 27, 2026
Merged

Add API to enable throwing in EmbeddedChannel.getOption and .setOption if channel is closed#3495
simonjbeaumont merged 3 commits intoapple:mainfrom
simonjbeaumont:sb/embedded-opt-in-throwing-options

Conversation

@simonjbeaumont
Copy link
Copy Markdown
Contributor

@simonjbeaumont simonjbeaumont commented Jan 26, 2026

Motivation:

Channels based on BaseSocketChannel throw in both getOption and setOption if the channel has been closed, since the setsockopt will fail. However, the current behavior of EmbeddedChannel is options remain writable and readable on closed channels.

There are situations where we'd like to be able to model the runtime behaviour of the real channel in tests, e.g. to test this fix: apple/swift-nio-extras#304.

Modifications:

  • Add API to enable throwing in EmbeddedChannel.getOption and .setOption if channel is closed.
  • Add a test for this new behavior.

Result:

  • New API to enable throwing in EmbeddedChannel.getOption and .setOption if channel is closed.
  • No observable change for existing users of EmbeddedChannel.

@simonjbeaumont simonjbeaumont added the 🆕 semver/minor Adds new public API. label Jan 26, 2026
@simonjbeaumont simonjbeaumont enabled auto-merge (squash) January 26, 2026 16:09
@simonjbeaumont simonjbeaumont force-pushed the sb/embedded-opt-in-throwing-options branch from 547af1a to fee03e2 Compare January 27, 2026 11:44
@simonjbeaumont simonjbeaumont merged commit 37ffc4b into apple:main Jan 27, 2026
54 checks passed
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/minor Adds new public API.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants