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

read: don't clear buffer when nothing can be read #739

Merged
merged 1 commit into from
May 5, 2024

Conversation

casperisfine
Copy link

To be consistent with regular Ruby IOs:

r, _ = IO.pipe
buf = "garbage".b
r.read_nonblock(10, buf, exception: false) # => :wait_readable
p buf # => "garbage"

Ref: redis-rb/redis-client@98b8944

@@ -1958,7 +1958,6 @@ ossl_ssl_read_internal(int argc, VALUE *argv, VALUE self, int nonblock)
else
rb_str_modify_expand(str, ilen - RSTRING_LEN(str));
}
rb_str_set_len(str, 0);
if (ilen == 0)
return str;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

str needs to be cleared here, when trying to read zero bytes (ilen == 0)

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah good catch. This wasn't called by the test because OpenSSL::Buffering just returns early if size == 0.

But I fixed it in case it's sometimes used without the buffering.

@rhenium
Copy link
Member

rhenium commented Apr 26, 2024

Good catch! I didn't know about this behavior on IO.

To be consistent with regular Ruby IOs:

```ruby
r, _ = IO.pipe
buf = "garbage".b
r.read_nonblock(10, buf, exception: false) # => :wait_readable
p buf # => "garbage"
```

Ref: redis-rb/redis-client@98b8944
@casperisfine
Copy link
Author

@rhenium thanks for the review and sorry for the delay, I was in vacation.

Should be good to go now.

@rhenium rhenium merged commit d2d6a99 into ruby:master May 5, 2024
53 checks passed
@rhenium
Copy link
Member

rhenium commented May 5, 2024

Yes, it looks good to me now. Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging this pull request may close these issues.

3 participants