Skip to content

Add explicit Crystal::EventLoop#reopened(FileDescriptor) hook #15640

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 1 commit into
base: master
Choose a base branch
from

Conversation

ysbaddaden
Copy link
Contributor

We don't want to close the file descriptor after we reopened it. Instead, some event loops want to resume the pending operations on the old file descriptor, so they can be restarted on the new file descriptor and at worst wait on the new one.

The proposed #reopened(FileDescriptor) method explicits this difference in intended behavior.

It doesn't change anything for the current event loops, but io_uring for example can close asynchronously so we must make the distinction, because we definitely don't want to close after reopen 😅

Another pull request will propose to move the actual close to the EventLoop so the #close(io) method will do what it's supposed to do (close the FileDescriptor / Socket).

Extracted from #15634

@Sija
Copy link
Contributor

Sija commented Apr 7, 2025

As it's a hook I'd suggest naming it on_reopen to make it more clear and conventional.

@ysbaddaden ysbaddaden mentioned this pull request Apr 7, 2025
15 tasks
@ysbaddaden
Copy link
Contributor Author

ysbaddaden commented Apr 8, 2025

I tried #after_reopen to be explicit that it was called after reopen, but that didn't read better than #reopened that also conveys this feeling. But #on_reopen would lost that information: does it happen before, after, during?

@Sija
Copy link
Contributor

Sija commented Apr 8, 2025

on_reopened then?

@straight-shoota
Copy link
Member

I think the method name is fine. Calling this methods signals to the event loop that a file descriptor was reopened.

@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