Project

General

Profile

Bug #9352

[BUG] rb_sys_fail_str(connect(2) for [fe80::1%lo0]:3000) - errno == 0

Added by kain (Claudio Poli) almost 6 years ago. Updated almost 6 years ago.

Status:
Closed
Priority:
Normal
Target version:
-
ruby -v:
ruby 2.1.0p0 (2013-12-25 revision 44422) [x86_64-darwin13.0]
[ruby-core:59498]

Description

I'm seeing this crash attempting to connect to an http unreachable host (127.0.0.1:3000) through Excon, which in turn uses connect_nonblock.

I'm compiling ruby-trunk at the moment, to try on it as well.


Files

ruby_2014-01-03-053648_kain-retina.crash (31.3 KB) ruby_2014-01-03-053648_kain-retina.crash crash report kain (Claudio Poli), 01/03/2014 01:55 PM
full_info.txt (411 KB) full_info.txt full info kain (Claudio Poli), 01/03/2014 01:55 PM
0001-socket-preserve-errno-before-rb_sys_fail_-and-friend.patch (2.34 KB) 0001-socket-preserve-errno-before-rb_sys_fail_-and-friend.patch normalperson (Eric Wong), 01/03/2014 04:35 PM

Associated revisions

Revision 8f045561
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44490 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

Revision 44490
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Revision 44490
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Revision 44490
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Revision 44490
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Revision 44490
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Revision 44490
Added by charliesome (Charlie Somerville) almost 6 years ago

  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Revision 1b05b4f4
Added by naruse (Yui NARUSE) almost 6 years ago

merge revision(s) 44490,44496: [Backport #9352]

    * ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
      before calling rb_sys_fail_str to prevent [BUG] errno == 0.
      Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

    * ext/socket/socket.c (rsock_sys_fail_path): ditto

    * ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

    * ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

    * ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

    * ext/socket/socket.c (rsock_syserr_fail_host_port): add errno
      argument version anduse rb_syserr_fail_str() instead of
      rb_sys_fail_str() with restoring errno.

    * ext/socket/socket.c (rsock_syserr_fail_path): ditto, and
      rb_syserr_fail().

    * ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto, use
      rsock_syserr_fail_raddrinfo().

    * ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto.

    * ext/socket/socket.c (setup_domain_and_type): ditto.

git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_2_1@44842 b2dd03c8-39d4-4d8f-98ff-823fe69b080e

History

Updated by kain (Claudio Poli) almost 6 years ago

Issue persists with ruby 2.2.0dev (2014-01-03 trunk 44488) [x86_64-darwin13.0]

Updated by normalperson (Eric Wong) almost 6 years ago

I can't reproduce the issue, but I think it has to do with calling functions which may clobber errno before
finally calling rb_sys_fail.

Can you try the attached patch (or pull request) against trunk?

$ git pull git://80x24.org/ruby.git sock-preserv-errno

The following changes since commit 12b09864056bfb961f06b0ef675b9fc2fabb9238:

  • properties. (2014-01-03 01:51:05 +0000)

are available in the git repository at:

git://80x24.org/ruby.git sock-preserv-errno

for you to fetch changes up to aaa0e88d55abcddfdf895508b86fe18e3d6b5cea:

socket: preserve errno before rb_sys_fail_* and friends (2014-01-03 07:24:35 +0000)


Eric Wong (1):
socket: preserve errno before rb_sys_fail_* and friends

ext/socket/socket.c | 13 +++++++++++++
1 file changed, 13 insertions(+)

Updated by tmm1 (Aman Gupta) almost 6 years ago

I can confirm Eric's patch fixes this [BUG] for me in faraday's test suite.

#4

Updated by charliesome (Charlie Somerville) almost 6 years ago

  • Status changed from Open to Closed
  • % Done changed from 0 to 100

This issue was solved with changeset r44490.
Claudio, thank you for reporting this issue.
Your contribution to Ruby is greatly appreciated.
May Ruby be with you.


  • ext/socket/socket.c (rsock_sys_fail_host_port): save and restore errno
    before calling rb_sys_fail_str to prevent [BUG] errno == 0.
    Patch by Eric Wong. [ruby-core:59498] [Bug #9352]

  • ext/socket/socket.c (rsock_sys_fail_path): ditto

  • ext/socket/socket.c (rsock_sys_fail_sockaddr): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo): ditto

  • ext/socket/socket.c (rsock_sys_fail_raddrinfo_or_sockaddr): ditto

Updated by charliesome (Charlie Somerville) almost 6 years ago

  • Status changed from Closed to Open
  • Assignee set to naruse (Yui NARUSE)
  • % Done changed from 100 to 0
  • Backport changed from 1.9.3: UNKNOWN, 2.0.0: UNKNOWN, 2.1: UNKNOWN to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED

Updated by normalperson (Eric Wong) almost 6 years ago

Thanks for testing. I can't say I like my patch, however, as
it's still error-prone and fragile.

How about some new functions to the C API:

rb_syserr_fail_str(VALUE mesg, int errnum);
rb_syserr_fail(const char *mesg, int errnum);

And deprecate rb_sys_fail and rb_sys_fail_str.

Updated by kain (Claudio Poli) almost 6 years ago

Thanks Eric, patch fixes the issue for me in ruby 2.2.0dev (2014-01-03 trunk 44490) [x86_64-darwin13.0]

Updated by tmm1 (Aman Gupta) almost 6 years ago

nobu (Nobuyoshi Nakada) cleaned up the patch in r44496, so that can be backported instead of r44490

Updated by naruse (Yui NARUSE) almost 6 years ago

  • Backport changed from 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: REQUIRED to 1.9.3: DONTNEED, 2.0.0: DONTNEED, 2.1: DONE

Updated by naruse (Yui NARUSE) almost 6 years ago

  • Status changed from Open to Closed

Also available in: Atom PDF