Issue #11600 has been updated by Nobuyoshi Nakada.

Description updated

Accurately, it is not a bug but a intentional crash.

Citing from [`libdispatch-442.1.4/src/source.c`](https://opensource.apple.com/tarballs/libdispatch/libdispatch-442.1.4.tar.gz):

~~~c
		int err = errno;
		switch (err) {
		case EMFILE:
			DISPATCH_CLIENT_CRASH("kqueue() failure: "
					"process is out of file descriptors");
			break;
		case ENFILE:
			DISPATCH_CLIENT_CRASH("kqueue() failure: "
					"system is out of file descriptors");
			break;
		case ENOMEM:
			DISPATCH_CLIENT_CRASH("kqueue() failure: "
					"kernel is out of memory");
			break;
		default:
			(void)dispatch_assume_zero(err);
			DISPATCH_CRASH("kqueue() failure");
			break;
		}
~~~


----------------------------------------
Bug #11600: indeterministic failures on socket operations when running out of file descriptors
https://bugs.ruby-lang.org/issues/11600#change-54477

* Author: Erkki Eilonen
* Status: Open
* Priority: Normal
* Assignee: 
* ruby -v: ruby 2.2.4p180 (2015-10-06 revision 52046) [x86_64-linux]
* Backport: 2.0.0: UNKNOWN, 2.1: UNKNOWN, 2.2: UNKNOWN
----------------------------------------
We've been getting indeterministic failures on socket operations when running out of file descriptors, instead of the correct `Errno::EMFILE` being raised we've seen various failure modes, on both linux and osx:

1. This is what we're seeing in production the most, masquerading as a dns failure

  >~~~
ruby test.rb 
1017 tempfiles
freeing 4
test.rb:24:in `getaddrinfo': getaddrinfo: Name or service not known (SocketError)
	from test.rb:24:in `block (3 levels) in <main>'

2.

  >~~~
>ruby test.rb 
1017 tempfiles
freeing 4
test.rb:24: [BUG] Άχ - errno == 0
ruby 2.2.4p180 (2015-10-06 revision 52046) [x86_64-linux]
>
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0009 e:000008 CFUNC  :getaddrinfo
c:0002 p:0018 s:0004 e:000003 BLOCK  test.rb:24 [FINISH]
c:0001 p:---- s:0002 e:000001 TOP    [FINISH]
>
-- Ruby level backtrace information ----------------------------------------
test.rb:24:in `block (3 levels) in <main>'
test.rb:24:in `getaddrinfo'

3.

>~~~
>ruby test.rb 
1017 tempfiles
freeing 4
test.rb:24: [BUG] rb_sys_fail(getaddrinfo) - errno == 0
ruby 2.2.4p180 (2015-10-06 revision 52046) [x86_64-linux]
>
-- Control frame information -----------------------------------------------
c:0003 p:---- s:0009 e:000008 CFUNC  :getaddrinfo
c:0002 p:0018 s:0004 e:000003 BLOCK  test.rb:24 [FINISH]
c:0001 p:---- s:0002 e:000001 TOP    [FINISH]
>
-- Ruby level backtrace information ----------------------------------------
test.rb:24:in `block (3 levels) in <main>'
test.rb:24:in `getaddrinfo'

Similar errors also happen doing other operations (eg `TCPSocket.open`)

Test case attached

---Files--------------------------------
test.rb (483 Bytes)
testcase.rb (431 Bytes)


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