Skip to content

Don't wait in io_binwrite_string if not necessary. #9792

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

Merged

Conversation

ioquatix
Copy link
Member

@ioquatix ioquatix commented Feb 1, 2024

https://bugs.ruby-lang.org/issues/20231

Indirectly responsible for socketry/async#301.

Writing to a buffered IO can result in the entire internal buffer being flushed, which causes io_binwrite_string_internal to return 0. In that case, we were setting errno = EAGAIN. This causes rb_io_maybe_wait_writable to be invoked, however we should immediately retry io_binwrite_string_internal instead, which is what this proposal implements.

The reason why calling rb_io_maybe_wait_writable is a bad idea in general, is that not all IO can go via this mechanism - in other words, kqueue does not support kevent("/dev/null", writable) and returns errno=22 EINVAL. The same applies to some kinds of pipes, TTYs, etc.

@ioquatix ioquatix merged commit 2554c5d into ruby:master Feb 1, 2024
@ioquatix ioquatix deleted the io_binwrite_string-retry-without-waiting branch February 1, 2024 02:27
github-merge-queue bot pushed a commit that referenced this pull request Feb 5, 2024
Don't wait in `io_binwrite_string` if not necessary. (#9792)

	---
	 io.c | 8 +++-----
	 1 file changed, 3 insertions(+), 5 deletions(-)
nagachika added a commit to nagachika/ruby that referenced this pull request Mar 31, 2024
	Don't wait in `io_binwrite_string` if not necessary. (ruby#9792)

	---
	 io.c | 8 +++-----
	 1 file changed, 3 insertions(+), 5 deletions(-)
@ioquatix ioquatix added this to the v3.4.0 milestone Nov 24, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant