Skip to content

Add a way to let other gems handle closing of fds in mruby-io#6231

Merged
matz merged 1 commit into
mruby:masterfrom
Asmod4n:add_close_fd_to_io
Apr 10, 2024
Merged

Add a way to let other gems handle closing of fds in mruby-io#6231
matz merged 1 commit into
mruby:masterfrom
Asmod4n:add_close_fd_to_io

Conversation

@Asmod4n

@Asmod4n Asmod4n commented Apr 7, 2024

Copy link
Copy Markdown
Contributor

I'm currently writing a gem which wants to integrate with mruby-io and mruby-socket.
At the moment mruby-io closes fds it didn't create itself and thus can cause problems when other gems except the fd to still be available.

This only changes how fptr_finalize handles the closing of fds and nothing else.
I've tried handling that in my gem by stopping a created mruby-io object from being garbage collected until it's not needed anymore, but that wasn't enough.

@Asmod4n
Asmod4n requested a review from matz as a code owner April 7, 2024 11:56
@Asmod4n

Asmod4n commented Apr 7, 2024

Copy link
Copy Markdown
Contributor Author

A short explanation: i'm writing a mruby gem to implement io_uring from linux.
This is fixing a otherwise impossible to handle race condition.

I've tried several ways to fix this in my gem, the only thing that worked is to mrb_gc_register every mruby-io object i created and never unregister them, because you can't know when its save to release them.

@matz
matz merged commit 0ad669e into mruby:master Apr 10, 2024
@Asmod4n
Asmod4n deleted the add_close_fd_to_io branch April 10, 2024 16:43
matz added a commit that referenced this pull request Apr 11, 2024
The `sizeof(struct mrb_io)` is reduced from 32 bytes to 24 bytes on
x86_64-linux.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants