[#56982] [ruby-trunk - Bug #8854][Open] Update URL for bug reports — "stomar (Marcus Stollsteimer)" <redmine@...>
7 messages
2013/09/03
[#57038] [ruby-trunk - Feature #3620] Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones — "Glass_saga (Masaki Matsushita)" <glass.saga@...>
4 messages
2013/09/05
[#57040] Re: [ruby-trunk - Feature #3620] Add Queue, SIzedQueue and ConditionVariable implementations in C in addition to ruby ones
— SASADA Koichi <ko1@...>
2013/09/05
(2013/09/05 20:52), Glass_saga (Masaki Matsushita) wrote:
[#57058] [ruby-trunk - Bug #8875][Open] Select is not usable with SSLSocket — "headius (Charles Nutter)" <headius@...>
11 messages
2013/09/07
[#57092] [ruby-trunk - Bug #8883][Open] Rational canonicalization unexpectedly converts to Fixnum — "melquiades (Paul Cantrell)" <cantrell@...>
16 messages
2013/09/09
[#57111] [ruby-trunk - Feature #8887][Open] min(n), max(n), min_by(n), max_by(n) — "akr (Akira Tanaka)" <akr@...>
13 messages
2013/09/10
[#57117] [ruby-trunk - Feature #8890][Open] [PATCH] Eliminate less-than-zero checks for unsigned variables — "tonyo (Anton Ovchinnikov)" <revolver112@...>
5 messages
2013/09/10
[#57134] [CommonRuby - Feature #8896][Open] #tap with missing block — "prijutme4ty (Ilya Vorontsov)" <prijutme4ty@...>
5 messages
2013/09/11
[#57138] [ruby-trunk - Feature #8897][Open] client side TCP fast open — "Glass_saga (Masaki Matsushita)" <glass.saga@...>
5 messages
2013/09/11
[#57195] [ruby-trunk - Feature #8897][Assigned] client side TCP fast open
— "Glass_saga (Masaki Matsushita)" <glass.saga@...>
2013/09/14
[#57186] [ruby-trunk - Feature #8909][Open] Expand "f" frozen suffix to literal arrays and hashes — "headius (Charles Nutter)" <headius@...>
37 messages
2013/09/14
[#57224] [ruby-trunk - Feature #8909] Expand "f" frozen suffix to literal arrays and hashes
— "headius (Charles Nutter)" <headius@...>
2013/09/15
[#57262] [ruby-trunk - Feature #8921][Open] Allow select, reject, etc to accept a regex — "kyledecot (Kyle Decot)" <kyle.decot@...>
13 messages
2013/09/18
[#57264] [ruby-trunk - Feature #8921] Allow select, reject, etc to accept a regex
— "kyledecot (Kyle Decot)" <kyle.decot@...>
2013/09/18
[#57265] Re: [ruby-trunk - Feature #8921] Allow select, reject, etc to accept a regex
— Fuad Saud <fuadksd@...>
2013/09/18
Shouldn't select/reject use threequals?
[#57292] [ruby-trunk - Feature #8931][Open] Update URL in REPORTBUG_MSG — "zzak (Zachary Scott)" <e@...>
4 messages
2013/09/20
[#57315] [ruby-trunk - Feature #8938][Open] it keyword — "Sing9898 (Sing Lou)" <3b06e8d4@...>
5 messages
2013/09/23
[#57367] [ruby-trunk - Feature #8951][Open] Please add a hash-to-hash alternative of the map method to Hash — "behrangsa (Behrang Saeedzadeh)" <behrangsa@...>
8 messages
2013/09/25
[#57385] [ruby-trunk - Bug #8953][Open] `str =~ /pattern/` does not call =~ method if (1) str is a String, (2) /pattern/ is a Regexp literal — "gfx (Goro Fuji)" <gfuji@...>
12 messages
2013/09/26
[#57394] [ruby-trunk - Bug #8955][Open] LocalJumpError - no block given (yield) after implementation of class hierarchy method cache invalidation — "mfla (Morten Fla)" <mmflaa@...>
4 messages
2013/09/26
[#57462] [ruby-trunk - misc #8962][Open] [DOC] add step to enable Generational GC merits in README.EXT* — "tad (Tadashi Saito)" <redmine@...>
6 messages
2013/09/28
[ruby-core:57071] [ruby-trunk - Bug #8875] Select is not usable with SSLSocket
From:
"headius (Charles Nutter)" <headius@...>
Date:
2013-09-08 14:14:24 UTC
List:
ruby-core #57071
Issue #8875 has been updated by headius (Charles Nutter). akr (Akira Tanaka) wrote: > 2013/9/8 headius (Charles Nutter) <headius@headius.com>: > > > In JRuby, my first fix was to make IO.select aware of SSLSocket's native buffers by adding a method to query if SSLSocket had buffered data itself. This adds the socket to the list of pending read streams and does not attempt to do a blocking select on it. This fixes the simple issue of sysread/sysread_nonblock reading more data than requested and potentially draining the stream and allows select to work correctly. > > I think the right fix is that application uses read_nonblock before select. > See the document of IO#read_nonblock and OpenSSL::Buffering#read_nonblock. > I wrote this problem in [ruby-core:38681]. I would agree, except that users are shown, through examples online and in source, that SSLSocket is "IO-like" and can be used anywhere an IO can be used. IO can do buffered IO and still be selectable. SSLSocket cannot. This is a shame because without the buffering in buffering.rb, it *would* be feasible to make select work with SSLSocket, as I have done in JRuby. > > However, the buffering issue is harder to fix. I believe buffering.rb needs to go away entirely, or at least needs to not buffer data on its own. > > OpenSSL::Buffering#gets may be difficult to implement efficiently > without buffering. Difficult but not impossible :-) If the buffer in buffering.rb was known to SSLSocket proper and SSLSocket included it when reporting to IO.select that it has data buffered, all would be fine. This could either mean moving the implementations of gets and friends into C code to work directly against the SSLSocket buffers, or moving @rbuffer into a native location so it can be efficiently queried for data. I may attempt to implement the latter proposal for JRuby, and then we could translate it for MRI. The bottom line is that there are too many buffers and not enough visibility into them. So we need to fix one thing or the other. - Charlie ---------------------------------------- Bug #8875: Select is not usable with SSLSocket https://bugs.ruby-lang.org/issues/8875#change-41683 Author: headius (Charles Nutter) Status: Open Priority: Normal Assignee: Category: ext/openssl Target version: ruby -v: all Backport: 1.9.3: UNKNOWN, 2.0.0: UNKNOWN Because of the various levels of buffering SSLSocket employs, it is not possible to reliably use IO.select to check when it has data available. SSLSocket wraps a normal IO that it uses for reading and writing unencrypted data. This IO has its own buffers, at the OS/libc level. Select normally operates against IO, checking whether data has been buffered or is available on the wire. However, in order to decrypt data on the wire, SSLSocket often needs to read more data than it needs, potentially draining the stream. This is problem #1. This problem can be mitigated by making IO.select know that it's an SSLSocket and that it may have its own buffers. However, there's another layer of buffering that happens in openssl/buffering.rb, where read, readpartial, read_nonblock, and methods that call them eventually hit fill_rbuf, which can easily drain both the IO buffers and the SSLSocket buffers into a Ruby-land buffer IO.select does not know about. An example script is here: https://gist.github.com/headius/6477345 In investigating why this hangs on JRuby (under the original assumption that it was a JRuby issue) I realized that fill_rbuff is reading 16k bytes at a time to try to fill its internal buffer. This effectively drains all data in all buffers visible to IO.select, causing select to hang after the first read. ruby-head (a few months old), Ruby 1.9.3p253, Ruby 1.8.7p358, JRuby (all versions), and Rubinius (all versions) are affected, because we all share buffering.rb which is where the problem lies. This may be a known issue, but we continue to get bug reports from Ruby users claiming JRuby is failing to support select + SSLSocket correctly. I'd like to figure out if there's anything we as a community can do to fix this. -- http://bugs.ruby-lang.org/