Skip to content
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

Avoid flush in finalizers for Socket and IO::FileDescriptor #14882

Conversation

straight-shoota
Copy link
Member

@straight-shoota straight-shoota commented Aug 8, 2024

Trying to flush means that it can try to write, hence call into the event loop, that may have to wait for the fd to be writable, which means calling into epoll_wait. This all while the world is stopped during a garbage collection run. The event loop implementation may need to allocate, or we get an error and try to raise an exception that will also try to allocate memory... again during a GC collection.

For Socket this change has little impact becase sync is true by default which means every byte is sent directly without buffering.
IO::FileDescriptor (and File) is buffered by default, so this may lead to loss of data if you don't properly close the file descriptor after use.

Resolves #14807

@straight-shoota straight-shoota self-assigned this Aug 8, 2024
@straight-shoota straight-shoota added kind:bug A bug in the code. Does not apply to documentation, specs, etc. and removed kind:chore labels Aug 8, 2024
@straight-shoota straight-shoota added this to the 1.14.0 milestone Aug 12, 2024
@straight-shoota straight-shoota merged commit d54a91f into crystal-lang:master Aug 13, 2024
62 checks passed
@straight-shoota straight-shoota deleted the fix/fd-socket-finalize-close branch August 13, 2024 21:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
breaking-change kind:bug A bug in the code. Does not apply to documentation, specs, etc. topic:stdlib:files
Projects
None yet
Development

Successfully merging this pull request may close these issues.

IO::FileDescriptor & Socket finalizers do far too much
2 participants