Skip to content

Let Crystal::EventLoop#close do the actual close (not just cleanup) #15641

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

ysbaddaden
Copy link
Contributor

Internal refactor to have the Crystal::EventLoop#close(io) implementations be responsible from actually closing the file descriptor or socket, not only do some internal cleanup before closing. They now follow the abstract methods documentation:

Closes the file descriptor|socket resource.

This will allow the io_uring event loop to close asynchronously.

Exposes the #close_volatile_fd? helper on UNIX that will prove helpful in io_uring.

Follow-up to #15640
Extracted from #15634

Internal refactor to have the `Crystal::EventLoop#close(io)`
implementations be responsible from actually closing the file descriptor
or socket, not only do some internal cleanup before closing.

This will allow the io_uring event loop to close asynchronously for
example.
@@ -131,7 +126,7 @@ module Crystal::System::FileDescriptor

# Clear the @volatile_fd before actually closing it in order to
# reduce the chance of reading an outdated fd value
_fd = @volatile_fd.swap(-1)
return unless _fd = close_volatile_fd?
Copy link
Contributor

Choose a reason for hiding this comment

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

Variables marked with leading underscore are conventionally treated as unused, also there's no need to do that here, why not just drop it?

ditto elsewhere

Copy link
Contributor Author

@ysbaddaden ysbaddaden Apr 8, 2025

Choose a reason for hiding this comment

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

No idea why it was used in the first place, maybe to convey the difference with the #fd method.

Copy link
Contributor

Choose a reason for hiding this comment

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

It's pretty common to shadow the instance variables / getters, though that's a minor suggestion overall.

Copy link
Contributor Author

@ysbaddaden ysbaddaden Apr 8, 2025

Choose a reason for hiding this comment

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

We probably should just use fd because we just poisoned @volatile_fd so #fd is invalid now anyway.

@straight-shoota straight-shoota added this to the 1.17.0 milestone Apr 15, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants