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

Take closeFuture into account when closing EventLoopGroup #231

Merged
merged 1 commit into from
Mar 26, 2018

Conversation

normanmaurer
Copy link
Member

Motiviation:

When the Selector is closed we also close the registered Channels and notify the future once all the close operations complete. The problem here is that while the close operation may be complete already there may still be events flowing through the ChannelPipeline. The only way to ensure this not happens anymore is to take the closeFuture into account of each Channel (as the closeFuture will only be notified once all is done for a Channel).

Modification:

  • Also take the closeFuture into account per Channel
  • Add test

Result:

Safer shutdown of EventLoopGroup.

@normanmaurer normanmaurer requested review from weissi and Lukasa March 26, 2018 08:00
@normanmaurer normanmaurer added this to the 1.4.0 milestone Mar 26, 2018
@normanmaurer normanmaurer added the 🔨 semver/patch No public API change. label Mar 26, 2018
return chan.close()
return chan.close().then {
chan.closeFuture
}
Copy link
Contributor

Choose a reason for hiding this comment

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

This has the effect of firing the future early if the close errors. We probably don't want to do that: presumably we should just close() and then return chan.closeFuture, rather than chaining through then?

Copy link
Member Author

Choose a reason for hiding this comment

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

@Lukasa yeah you are right... let me do this.

XCTAssertFalse(channel.closeFuture.isFulfilled)
try group.syncShutdownGracefully()
XCTAssertTrue(channel.closeFuture.isFulfilled)
XCTAssertFalse(channel.isActive)
Copy link
Contributor

Choose a reason for hiding this comment

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

This test would probabilistically pass before the given change: it relies on a race between syncShutdownGracefully returning and the check on the state of channel.closeFuture and channel.isActive. These checks should probably be done by inserting a channel handler that catches close and checks whether syncShutdownGracefully has returned yet. It may even want to wait a few ms to be sure.

Copy link
Member Author

Choose a reason for hiding this comment

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

@Lukasa good idea... I think we should add the check in channelInactive(...) tho. WDYT ?

Copy link
Member Author

Choose a reason for hiding this comment

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

Actually handlerRemoved(...)

Motiviation:

When the Selector is closed we also close the registered Channels and notify the future once all the close operations complete. The problem here is that while the close operation may be complete already there may still be events flowing through the ChannelPipeline. The only way to ensure this not happens anymore is to take the closeFuture into account of each Channel (as the closeFuture will only be notified once all is done for a Channel).

Modification:

- Also take the closeFuture into account per Channel
- Add test

Result:

Safer shutdown of EventLoopGroup.
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.

LGTM, thanks!

@Lukasa Lukasa merged commit c3fc78f into apple:master Mar 26, 2018
@normanmaurer normanmaurer deleted the closefuture_grace branch March 26, 2018 18:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
🔨 semver/patch No public API change.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants