Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add closeOnDeinit to the NIOAsyncChannel init #2592

Merged

Conversation

FranzBusch
Copy link
Member

Motivation

In my previous PR, I already did the work to add finishOnDeinit configuration to the NIOAsyncWriter and NIOAsyncSequenceProducer. This PR also automatically migrated the NIOAsyncChanell to set the finishOnDeinit = false. This was intentional since we really want users to not use the deinit based cleanup; however, it also broke all current adopters of this API semantically and they might now run into the preconditions.

Modification

This PR reverts the change in NIOAsyncChannel and does the usual deprecate + new init dance to provide users to configure this behaviour while still nudging them to check that this is really what they want.

Result

Easier migration without semantically breaking current adopters of NIOAsyncChannel.

@FranzBusch FranzBusch added the semver/minor Adds new public API. label Nov 14, 2023
# Motivation
In my previous PR, I already did the work to add `finishOnDeinit` configuration to the `NIOAsyncWriter` and `NIOAsyncSequenceProducer`. This PR also automatically migrated the `NIOAsyncChanell` to set the `finishOnDeinit = false`. This was intentional since we really want users to not use the deinit based cleanup; however, it also broke all current adopters of this API semantically and they might now run into the preconditions.

# Modification
This PR reverts the change in `NIOAsyncChannel` and does the usual deprecate + new init dance to provide users to configure this behaviour while still nudging them to check that this is really what they want.

# Result
Easier migration without semantically breaking current adopters of `NIOAsyncChannel`.
@FranzBusch FranzBusch force-pushed the fb-async-channel-deinit-based-cleanup branch from cec1a4c to 1dbbec2 Compare November 14, 2023 14:17
@FranzBusch FranzBusch changed the title Add finishOnDeinit to the NIOAsyncChannel init Add closeOnDeinit to the NIOAsyncChannel init Nov 14, 2023
public init(
synchronouslyWrapping channel: Channel,
configuration: Configuration = .init(),
closeOnDeinit: Bool
Copy link
Contributor

Choose a reason for hiding this comment

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

It's a shame we have to rely on users setting this to get the right behaviour because they can still set this to be true and get the old behaviour without a deprecation warning.

Ideally users shouldn't have to think about this and we would have two differently spelled inits, the deprecated old one and the new no-close-on-deinit one. That'd make it obvious which one to call.

I'm not sure what to suggest for naming here, however. A couple of ideas (don't love either):

  • a static helper static func synchronouslyWrapping(_:configuration:) -> Self
  • init(wrappingChannelSynchronously:configuration:)

Copy link
Member

Choose a reason for hiding this comment

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

It's a shame we have to rely on users setting this to get the right behaviour because they can still set this to be true and get the old behaviour without a deprecation warning.

Yes.

Ideally users shouldn't have to think about this and we would have two differently spelled inits, the deprecated old one and the new no-close-on-deinit one. That'd make it obvious which one to call.

I think you're right

Copy link
Member Author

Choose a reason for hiding this comment

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

I agree with those points. I had it quickly prototyped with a factory method but disliked it. Maybe just having a wrappingChannelSynchronously is the way out :D

@yim-lee
Copy link
Member

yim-lee commented Nov 14, 2023

@swift-server-bot test this please

Copy link
Contributor

@glbrntt glbrntt left a comment

Choose a reason for hiding this comment

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

LGTM aside from the now redundant docs

Comment on lines 102 to 103
/// - closeOnDeinit: Indicates if the underlying channel should be closed once the `inbound` and `outbound` have been deinited. We do not recommend to rely on
/// deinit based resource tear down.
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: kill these docs

/// - Parameters:
/// - channel: The ``Channel`` to wrap.
/// - configuration: The ``NIOAsyncChannel``s configuration.
/// - closeOnDeinit: Indicates if the underlying channel should be closed once the `inbound` and `outbound` have been deinited. We do not recommend to rely on
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: kill these docs

@FranzBusch FranzBusch enabled auto-merge (squash) November 14, 2023 17:50
@FranzBusch FranzBusch force-pushed the fb-async-channel-deinit-based-cleanup branch from 382cd83 to 9f09e39 Compare November 14, 2023 17:50
@FranzBusch
Copy link
Member Author

@swift-server-bot test this please

@FranzBusch FranzBusch force-pushed the fb-async-channel-deinit-based-cleanup branch from 9f09e39 to 148ba68 Compare November 15, 2023 12:56
@FranzBusch FranzBusch force-pushed the fb-async-channel-deinit-based-cleanup branch from 148ba68 to 0f9d376 Compare November 15, 2023 13:09
@FranzBusch FranzBusch merged commit 1040927 into apple:main Nov 15, 2023
6 of 8 checks passed
@FranzBusch FranzBusch deleted the fb-async-channel-deinit-based-cleanup branch November 15, 2023 13:42
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.

None yet

4 participants