ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
* [ruby-core:90339] [Ruby trunk Bug#15386] [PATCH] io.c (rb_io_check_char_readable): do not io_fflush buffered sockets
       [not found] <redmine.issue-15386.20181206113800@ruby-lang.org>
@ 2018-12-06 11:38 ` normalperson
  0 siblings, 0 replies; only message in thread
From: normalperson @ 2018-12-06 11:38 UTC (permalink / raw)
  To: ruby-core

Issue #15386 has been reported by normalperson (Eric Wong).

----------------------------------------
Bug #15386: [PATCH] io.c (rb_io_check_char_readable): do not io_fflush buffered sockets
https://bugs.ruby-lang.org/issues/15386

* Author: normalperson (Eric Wong)
* Status: Open
* Priority: Normal
* Assignee: 
* Target version: 
* ruby -v: 
* Backport: 2.4: UNKNOWN, 2.5: UNKNOWN
----------------------------------------
```
This is a rare corner-case probably nobody cares about. (because
socket has IO#sync=false by default).  Not critical to fix
or change before 2.6 (I'm not sure if there's a compatibility risk).

Would much appreciate an extra set of eyes to review; but it can wait
for post-26.

[I tried taking a break from C and ruby-core to work on a different
 project today; but hit this bug within an hour of doing that :<]


io.c (rb_io_check_char_readable): do not io_fflush buffered sockets

I enabled userspace buffering on sockets to reduce syscall
overhead while avoiding non-portable TCP_CORK/TCP_NOPUSH.
This deadlocked for me because I was using independent threads
for reading and writing simultaneously on the same socket.

I also experimented with making io_fflush optionally
non-blocking, but that caused stream corruption with the reader
thread doing some writes.

  https://80x24.org/spew/20181206104008.29153-1-e@80x24.org/raw

Test script (hitting
  news://news.public-inbox.org/inbox.comp.version-control.git
  is fine)

require 'socket'
require 'uri'
require 'io/nonblock'
usage = "usage: #$0 news://news.public-inbox.org/inbox.comp.version-control.git"
uri = ARGV.shift or abort usage
uri = URI(uri)
uri.port ||= 119
group = uri.path.sub(%r{\A/+}, '') # String#delete_prefix requires Ruby 2.5+
s = Socket.tcp(uri.host, uri.port)
l = s.gets
l =~ /\A2\d\d / or abort "bad greeting: #{l}"
s.nonblock = true

s.puts "GROUP #{group}"
l = s.gets
code, _, min, max = l.chomp!.split.map!(&:to_i)
code == 211 or abort "bad GROUP response: #{l}"
rdr = Thread.new do
  nres = 0
  r = s.dup
  while l = r.gets
    l.start_with?('205 ') and break # cmd_quit
    l.start_with?('224 ') or abort "bad OVER response: #{l}"
    while l = r.gets
      if l == ".\r\n"
        nres += 1
        break
      end
    end
  end
  nres
end

range = min..max
s.sync = false
range.each { |i| s.puts "XOVER #{i}" }
puts "requests=#{range.size} #{Time.now}"
s.puts "QUIT"
s.flush
puts "responses=#{rdr.value} #{Time.now}"
```


---Files--------------------------------
0001-io.c-rb_io_check_char_readable-do-not-io_fflush-buff.patch (3.14 KB)


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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2018-12-06 11:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
     [not found] <redmine.issue-15386.20181206113800@ruby-lang.org>
2018-12-06 11:38 ` [ruby-core:90339] [Ruby trunk Bug#15386] [PATCH] io.c (rb_io_check_char_readable): do not io_fflush buffered sockets normalperson

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).