Bug #4933

winsock listen backlog may only be set once, and is set to 5

Added by ghazel (Greg Hazel) almost 9 years ago. Updated almost 9 years ago.

Target version:
ruby -v:
ruby 1.8.7 (2011-02-18 patchlevel 334) [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.

"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:

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):
Unicorn uses 1024:
Tornado uses 128:
EventMachine uses 100:
Twisted uses 50:


listen_backlog_increase.patch (361 Bytes) listen_backlog_increase.patch ghazel (Greg Hazel), 06/27/2011 07:51 AM

Related issues

Is duplicate of Ruby master - Bug #4934: winsock listen backlog may only be set once, and is set to 5Closed06/27/2011akr (Akira Tanaka)Actions

Updated by shyouhei (Shyouhei Urabe) almost 9 years ago

  • Status changed from Open to Closed

OK, I see. But the bug is a dup of #4934 (with different ruby version). To avoid confusion, I close this for now. Once #4934 is fixed, this one can be reopened and I can backport that fix to 1.8.


Updated by ghazel (Greg Hazel) almost 9 years ago

Here is a patch to set the default value to 1024.

Also available in: Atom PDF