Repository navigation
Conversation
| BIO_clear_retry_flags(p->bio); | ||
|
|
||
| VALUE fargs[] = { INT2NUM(p->dlen), nonblock_kwargs }; | ||
| VALUE ret = rb_funcallv_public_kw(io, rb_intern("read_nonblock"), |
There was a problem hiding this comment.
should't this ret be somhow marked so it's not moved? (thinking of compaction here).
probably too early for optimizations, ,but this bit could benefit of a socket-local string to act as a buffer (second argument of :read_nonblock)
There was a problem hiding this comment.
The content is copied in this function and the String object won't be kept, so it shouldn't be necessary.
probably too early for optimizations, ,but this bit could benefit of a socket-local string to act as a buffer (second argument of
:read_nonblock)
Yes, this is definitely a possible optimization.
There was a problem hiding this comment.
It now reuses the String objects in bio_read() and bio_write() (which means additional 2x 16 KiB memory usage per SSLSocket which I think is acceptable).
| rb_io_set_nonblock(fptr); | ||
| } | ||
| else { | ||
| // Not meant to be a comprehensive check |
There was a problem hiding this comment.
as per the BIO impl, shouldn't this also verify "#flush"? (hypothetically, understand this wasn't as exhaustive check).
There was a problem hiding this comment.
I removed this check because I think it wasn't very useful anyway. Also #flush is optional now.
There was a problem hiding this comment.
Actually #flush was not necessary at all here, since all we use is #write_nonblock.
|
@rhenium anything I can help with to move this forward? |
|
@rhenium friendly ping |
ded7cb0 to
84ead32
Compare
|
I just pushed what I have in my local branch so far, rebased on top of current master to resolve merge conflicts. This is not ready to merge yet. Some unresolved issues:
|
Indeed, I didn't know that doing that was dangerous, though that One option could be to assume that the IO-like object must indeed be an SSLSocket, and one could deal with it by setting an ivar "flag" telling the internal implementation to skip 2nd-level
Can they happen at the same time? Perhaps suggestion above deals with it? An alternative approach could be to go back to the drawing board and try again the approach using |
Please see I think the segfault is fixable by (ab)using
|
|
Sorry for not replying sooner, have been stumped with other chores. I think "last exception wins" is reasonable, and considering this is a new feature, it's not really breaking compatibility. Lmk when you work around the jump tag issue, I can run a few sanity checks on my side as well. |
|
This branch needs more polishing, but it should be working aside from some edge cases. I'd appreciate if you could test it. I should have worded more accurately, but the last commit changed it so that the later tag jump (which includes raising an exception) wins against the former one. This should fix the segfault. One concern is that this can accidentally suppress an important jump like the one created by I haven't come up with a nice solution for this. |
|
just a heads-up that I've been trying to incorporate this in my branch's CI, but having issues due to C extension compilation and openssl being an stdlib I guess (opened a ticket here, in case you know why that happens and can recommend a workaround). |
That Gemfile snippet works as expected for me (ruby-build Ruby 3.4 on Linux). I'm not sure why it's failing for you. What happens if you clone the repository, run |
|
I did some effort to build openssl from branch in I may only be able to do some investigation in one week. |
I was able to reproduce it locally. This is a bug in |
|
thx, tests are passing now 👍 |
|
Just spent the day scratching my head over Net::HTTP's behavior around proxies and didn't see the tickets that led to this PR until now lol |
d8004f4 to
c9a1830
Compare
a7484c4 to
1b18f46
Compare
ea4145b to
be11a86
Compare
be11a86 to
7722d48
Compare
7722d48 to
bf8c2a3
Compare
When SSLSocket#connect or #accept is called for the first time, we pass the file descriptor to OpenSSL. Keep a reference to the corresponding IO object.
Raise an exception before calling SSL_*() if the underlying socket IO object has been unexpectedly closed. This avoids accidentally reading from or writing to a reused file descriptor. Also check the IO object's status before returning from callbacks to OpenSSL. Since a callback cannot reliably stop OpenSSL from using the underlying socket, we resort to invalidating the BIO object. Fixes ruby#1156
Make the following methods optional on the underlying socket, in
preparation for accepting IO-like objects as the underlying socket:
- #remote_address: use a placeholder string, as we do when the
underlying socket has already been closed.
- #timeout: assume nil.
- #sync: assume true.
Currently, OpenSSL::SSL::SSLSocket.new requires a T_FILE object because we pass the file descriptor to OpenSSL. Relax this and allow any Ruby object that responds to Ruby's standard non-blocking IO interface, namely: - write_nonblock, read_nonblock - wait_readable, wait_writable - close, closed? This adds a custom BIO_METHOD that maps BIO operations to Ruby method calls. The current BIO_s_socket() BIO_METHOD is still used for a T_FILE object because it is more efficient.
bf8c2a3 to
16d7043
Compare
An implementation of #731. The test suite passes on my box, but it needs more testing especially around the error handling.
This adds support for IO-like object that is not backed by a file descriptor by defining a
BIO_METHODto wrap the following Ruby methods.