ruby-core@ruby-lang.org archive (unofficial mirror)
 help / color / mirror / Atom feed
From: normalperson@yhbt.net
To: ruby-core@ruby-lang.org
Subject: [ruby-core:90339] [Ruby trunk Bug#15386] [PATCH] io.c (rb_io_check_char_readable): do not io_fflush buffered sockets
Date: Thu, 06 Dec 2018 11:38:01 +0000 (UTC)	[thread overview]
Message-ID: <redmine.issue-15386.20181206113800.d3a128b3233c239a@ruby-lang.org> (raw)
In-Reply-To: redmine.issue-15386.20181206113800@ruby-lang.org

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/

           reply	other threads:[~2018-12-06 11:38 UTC|newest]

Thread overview: expand[flat|nested]  mbox.gz  Atom feed
 [parent not found: <redmine.issue-15386.20181206113800@ruby-lang.org>]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-list from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.ruby-lang.org/en/community/mailing-lists/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=redmine.issue-15386.20181206113800.d3a128b3233c239a@ruby-lang.org \
    --to=ruby-core@ruby-lang.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).