socketry / nio4r

Cross-platform asynchronous I/O primitives for scalable network clients and servers.
Other
964 stars 85 forks source link

Allow calling `deregister` on closed IO objects #216

Closed Jesus closed 5 years ago

Jesus commented 5 years ago

Only JRuby would throw an exception when trying to deregister a closed stream. With this patch, JRuby's implementation will behave just like the other platforms.

Closes #215.

Jesus commented 5 years ago

This patch catches the error and exits early, this is safe if we assume that the IO object will be removed before waiting on select() because it's been closed.

I've checked this with code by calling empty? on the selector but I'd feel safer if you can confirm it will.

tarcieri commented 5 years ago

@headius @enebo seems my last message got eaten by some commits changing the code, but this seems a bit tricky - we need to cancel the associated selection key in this case, but can't locate it because we can't recover the original channel. Any thoughts on what to do here?