From: Greg Hazel Date: 2011-06-27T07:22:46+09:00 Subject: [ruby-core:37547] [Ruby 1.9 - Bug #4934] winsock listen backlog may only be set once, and is set to 5 Issue #4934 has been updated by Greg Hazel. Also set on win32 in ruby for socketpair here: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/win32/win32.c?view=markup&pathrev=27529#l3365 ---------------------------------------- Bug #4934: winsock listen backlog may only be set once, and is set to 5 http://redmine.ruby-lang.org/issues/4934 Author: Greg Hazel Status: Open Priority: Normal Assignee: Category: Target version: ruby -v: ruby 1.9.3dev (2011-06-17 trunk 32136) [i386-mingw32] This is commonly observed as a bug in Windows servers, where under light load clients begin to get ECONNREFUSED. This occurs even if the listen backlog is set to a high value, like 1024. The bug is that Ruby sets the value to 5 on creation of a TCPServer socket, and it is not valid in Winsock to set the listen backlog size a second time. From: http://msdn.microsoft.com/en-us/library/ms739168(v=vs.85).aspx "If the listen function is called on an already listening socket, it will return success without changing the value for the backlog parameter." Here's where ruby sets it: http://svn.ruby-lang.org/cgi-bin/viewvc.cgi/trunk/ext/socket/ipsocket.c?view=markup&pathrev=27529#l107 So one of two things needs to happen. Either: - on WIN32 Ruby should avoid setting the listen backlog by default, which would allow the user to choose the value but could conceivably break applications where were being lazy and not setting it at all - on WIN32 and maybe all platforms, Ruby should set the default listen backlog to SOMAXCONN (or something large) instead of 5. This will not break any existing code today, as an overly high listen backlog is not really a problem. Other default listen backlog values of servers: Mongrel tries to use 1024 (but silently fails on Windows because of this bug): https://github.com/mongrel/mongrel/blob/74290abc9ebd287542b2dcc0133fa41d33e5177b/lib/mongrel/tcphack.rb#L13 Unicorn uses 1024: https://github.com/defunkt/unicorn/blob/b3b6b0dff19f8a22a96525bba22bf061d03c3fc5/lib/unicorn/socket_helper.rb#L27 Tornado uses 128: https://github.com/facebook/tornado/blob/9d1af05323f9a7941e2336ce50972de65e18bcdd/tornado/httpserver.py#L214 EventMachine uses 100: https://github.com/eventmachine/eventmachine/blob/master/ext/em.cpp#L1539 Twisted uses 50: http://twistedmatrix.com/trac/browser/tags/releases/twisted-11.0.0/twisted/internet/tcp.py#L828 -- http://redmine.ruby-lang.org