Skip to content

Conversation

@felixschlegel
Copy link
Contributor

@felixschlegel felixschlegel commented May 17, 2023

Motivation

In swift-nio-ssl, I am currently working on allowing half-closures which rely on querying the underlying channel if ChannelOptions.Types.AllowRemoteHalfClosureOption is enabled. As a lot of
swift-nio-ssl's tests rely on EmbeddedChannel, which did not support this option, they failed failed due to a fatalError.

Modifications

  • add a public var allowRemoteHalfClosure to EmbeddedChannel
  • enable setting/getting
    ChannelOptions.Types.AllowRemoteHalfClosureOption in
    EmbeddedChannel (only modifies the allowRemoteHalfClosure variable
  • add test for new behaviour

internal func getOptionSync<Option: ChannelOption>(_ option: Option) -> Option.Value {
if option is ChannelOptions.Types.AutoReadOption {
if option is ChannelOptions.Types.AutoReadOption
|| option is ChannelOptions.Types.AllowRemoteHalfClosureOption {
Copy link
Contributor

Choose a reason for hiding this comment

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

I know I gave you this advice, so this is really my fault, but I no longer think this behaviour is quite right. 😁

I think we should allow the user of EmbeddedChannel to have a public var that they can set which provides the value of AllowRemoteHalfClosureOption. That lets tests configure whether the behaviour should be supported or not. This also lets us support setOption for this option.

Relatedly, the default value should be false.

Copy link
Contributor Author

@felixschlegel felixschlegel May 17, 2023

Choose a reason for hiding this comment

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

That makes sense 😄! I have pushed the new changes (amended to my old commit)!

@felixschlegel felixschlegel force-pushed the fs-embedded-get-option-add-allow-remote-half-closure branch from 53ae2d9 to be337ff Compare May 17, 2023 15:26
@Lukasa Lukasa added the 🆕 semver/minor Adds new public API. label May 19, 2023
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Great, this looks really good. Can I ask you to make the same enhancement to AsyncTestingChannel as well? That will keep the two interfaces in step.

Motivation:

In `swift-nio-ssl`, I am currently working on allowing half-closures
which relies on querying the underlying channel if
`ChannelOptions.Types.AllowRemoteHalfClosureOption` is enabled. As a lot of
`swift-nio-ssl`'s tests rely on `EmbeddedChannel` and it did not support
this option, a lot of the tests failed.

Modifications:

* add a `public var allowRemoteHalfClosure` to `EmbeddedChannel`
* enable setting/getting
  `ChannelOptions.Types.AllowRemoteHalfClosureOption` in
`EmbeddedChannel` (only modifies the `allowRemoteHalfClosure` variable
* add test for new behaviour
Motivation:

`AsyncTestingChannel` interface should be in step with `EmbeddedChannel`
interface. Therefore also add support for the
`AllowRemoteHalfClosureOption`

Modifications:

* add a `public var allowRemoteHalfClosure` to `AsyncTestingChannel`
* enable setting/getting
  `ChannelOptions.Types.AllowRemoteHalfClosureOption` in `AsyncTestingChannel`
  (only modifies the `allowRemoteHalfClosure` variable
* add tests for new behaviour
@felixschlegel felixschlegel force-pushed the fs-embedded-get-option-add-allow-remote-half-closure branch from be337ff to 7560113 Compare May 19, 2023 12:26
@felixschlegel felixschlegel requested a review from Lukasa May 19, 2023 12:27
public var isActive: Bool { return channelcore.isActive }

/// - see: `ChannelOptions.Types.AllowRemoteHalfClosureOption`
public var allowRemoteHalfClosure: Bool = false
Copy link
Contributor

Choose a reason for hiding this comment

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

This needs synchronization around it. Can you follow the pattern we used for isActive?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks for pointing that out! Have moved allowRemoteClosure to EmbeddedChannelCore now!

Modifications:

* add `ManagedAtomic` property `_allowRemoteHalfClosure` to
  `EmbeddedChannelCore`
* make sure that access to `allowRemoteHalfClosure` from
  `AsyncTestingChannel` and `EmbeddedChannel` is synchronized by
  accessing underlying atomic value in `channelcore`
@felixschlegel felixschlegel requested a review from Lukasa May 19, 2023 13:36
Copy link
Contributor

@Lukasa Lukasa left a comment

Choose a reason for hiding this comment

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

Fantastic!

@Lukasa
Copy link
Contributor

Lukasa commented May 19, 2023

@swift-server-bot add to allowlist

@Lukasa
Copy link
Contributor

Lukasa commented May 19, 2023

Can you update the allocation limits?

@Lukasa Lukasa enabled auto-merge (squash) May 19, 2023 16:24
@Lukasa Lukasa merged commit 47b6289 into apple:main May 19, 2023
Lukasa added a commit to Lukasa/swift-nio-http2 that referenced this pull request Jun 23, 2023
Allocations regressed due to our use of EmbeddedChannel, which
now uses a new atomic since apple/swift-nio#2429. We can update
the limits accordingly.
Lukasa added a commit to Lukasa/swift-nio-ssh-1 that referenced this pull request Jun 23, 2023
Allocations regressed due to our use of EmbeddedChannel, which now
uses a new atomic since apple/swift-nio#2429. We can update the
limits accordingly.
Lukasa added a commit to apple/swift-nio-ssh that referenced this pull request Jun 23, 2023
Allocations regressed due to our use of EmbeddedChannel, which now
uses a new atomic since apple/swift-nio#2429. We can update the
limits accordingly.
Lukasa added a commit to apple/swift-nio-http2 that referenced this pull request Jun 23, 2023
Allocations regressed due to our use of EmbeddedChannel, which
now uses a new atomic since apple/swift-nio#2429. We can update
the limits accordingly.
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