-
Notifications
You must be signed in to change notification settings - Fork 6
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
Make IOServerSocketChannel#accept
cancelable
#31
Conversation
test("IOServerSocketChannel.accept is cancelable") { | ||
// note that this test targets IOServerSocketChannel#accept, | ||
// not the underlying AsynchronousSocketChannel#accept implementation | ||
IOServerSocketChannel | ||
.open | ||
.evalTap(_.bind(new InetSocketAddress(0))) | ||
.flatMap(_.accept) | ||
.use_ | ||
.timeout(100.millis) | ||
.intercept[TimeoutException] | ||
} |
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.
I could reproduce this issue on the JVM as well. It's not an issue with our implementation in epollcat, it's an issue with the fact that accept
is not cancelable.
IO.async { cb => | ||
IO(ch.accept(null, toHandler(cb))) | ||
// it seems the only way to cancel accept is to close the socket :( | ||
.as(Some(IO(ch.close()))) | ||
} |
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.
The fundamental issue is that there is no good way with the JDK APIs to cancel a pending accept
(which is really dumb to be honest). Some googling suggested that closing the channel is the only way to do so.
This is very ugly, but it is good enough for our tests ... I think.
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.
I think the close()
is entirely good, not just good enough. What would one do
with the now messed-up listen socket anyway? Like a mayfly, its purpose was
singular and brief.
I think in C one would send a signal, yeech!
Thank you for fixing this.
Would you like to try it out or are you sufficiently satisfied?
Thanks! If you're happy I'm happy :) |
I think I will be causing enough failures over the near future that I well |
I think this also ends Issue #28. I ran this PR in my "provoke connect' failure X86_64 environment This leaves Issue #20 as still relevant but at lesser severity. |
Fixes #21. I think :)
This was more of a problem with our tests than the actual implementation. But it definitely warrants discussion.
The reason for the hang was that Cats Effect will never "fire-and-forget" by default: if there is an error, it will cancel other running fibers (aka green threads) and wait for their cancellation. If an action is not cancelable, then it will wait until that action either completes or errors before canceling that fiber.
Since
accept
was not cancelable if fell into this trap.