-
Notifications
You must be signed in to change notification settings - Fork 656
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
Conversation
18eb7d4
to
cb28d82
Compare
Sources/NIO/Selector.swift
Outdated
return chan.close() | ||
return chan.close().then { | ||
chan.closeFuture | ||
} |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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.
Tests/NIOTests/EventLoopTest.swift
Outdated
XCTAssertFalse(channel.closeFuture.isFulfilled) | ||
try group.syncShutdownGracefully() | ||
XCTAssertTrue(channel.closeFuture.isFulfilled) | ||
XCTAssertFalse(channel.isActive) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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 ?
There was a problem hiding this comment.
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.
cb28d82
to
25cdd3d
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
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:
Result:
Safer shutdown of EventLoopGroup.