Skip to content

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

Merged
straight-shoota merged 1 commit intocrystal-lang:masterfrom
ysbaddaden:feature/event-loop-reopened-hook
Apr 17, 2025
Merged

Add explicit Crystal::EventLoop#reopened(FileDescriptor) hook#15640
straight-shoota merged 1 commit intocrystal-lang:masterfrom
ysbaddaden:feature/event-loop-reopened-hook

Conversation

@ysbaddaden
Copy link
Collaborator

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
21 tasks
@ysbaddaden
Copy link
Collaborator 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
@straight-shoota straight-shoota merged commit 0805dc4 into crystal-lang:master Apr 17, 2025
36 checks passed
@ysbaddaden ysbaddaden deleted the feature/event-loop-reopened-hook branch April 17, 2025 17:52
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