Skip to content
New issue

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

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

Already on GitHub? # to your account

Close Channel when input & output are closed #2450

Merged

Conversation

felixschlegel
Copy link
Contributor

Motivation:

Suppose we have a channel whose input and output are closed.
On Linux, this currently results in a full socket closure (which means
TCP RST is being sent). This behaviour is currently different
on Darwin because we don't close our socket here when our input and output are
closed.

We should not have two different platform-dependent behaviours here.

As we cannot suppress the TCP RST on Linux, we have to align the
Darwin behaviour to the Linux behaviour meaning we close
our entire NIO channel when both the input and the output are closed.

Modifications:

  • BaseStreamSocketChannel: escalate to full closure when both its
    input and its output are closed
  • add new test
    ChannelTests.testInputAndOutputClosedResultsInFullClosure()
    verifying the desired behaviour

Result:

BaseStreamSocketChannel will now close entirely when both input and
output are closed.

Motivation:

Suppose we have a channel whose input and output are closed.
On Linux, this currently results in a full socket closure (which means
TCP `RST` is being sent). This behaviour is currently different
on Darwin because we don't close our socket here when our input and output are
closed.

We should not have two different platform-dependent behaviours here.

As we cannot suppress the TCP `RST` on Linux, we have to align the
Darwin behaviour to the Linux behaviour meaning we close
our entire NIO channel when both the input and the output are closed.

Modifications:

* `BaseStreamSocketChannel`: escalate to full closure when both its
  input and its output are closed
* add new test
  `ChannelTests.testInputAndOutputClosedResultsInFullClosure()`
  verifying the desired behaviour

Result:

`BaseStreamSocketChannel` will now close entirely when both input and
output are closed.
@felixschlegel felixschlegel force-pushed the fs-align-closing-on-darwin-with-linux branch from 67c90d3 to 892daec Compare June 23, 2023 09:56
felixschlegel added a commit to felixschlegel/swift-nio-ssl that referenced this pull request Jun 23, 2023
Modifications:

* `NIOSSLIntegrationTest.testCloseModeOutputServerAndClient`: remove
  `clientChannel.close` statement, as closing input and output of a
  channel results in full closure per `swift-nio` patch
  [#2450](apple/swift-nio#2450)
felixschlegel added a commit to felixschlegel/swift-nio-ssl that referenced this pull request Jun 23, 2023
Modifications:

* `NIOSSLIntegrationTest.testCloseModeOutputServerAndClient`: remove
  `clientChannel.close` statement, as closing input and output of a
  channel results in full closure per `swift-nio` patch
  [#2450](apple/swift-nio#2450)
@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Jun 26, 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.

Can you extend the test to confirm that the server shuts down too?

Modifications:

* `testInputAndOutputClosedResultsInFullClosure`:
    * prefix all server related variables with `server*`
    * assert that `serverConnectionChildChannel` becomes inactive once
      the `clientConnectionChannel` is fully closed
@felixschlegel felixschlegel requested a review from Lukasa June 26, 2023 14:09
@Lukasa Lukasa enabled auto-merge (squash) June 29, 2023 09:09
@Lukasa Lukasa merged commit 2ab7332 into apple:main Jun 29, 2023
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants