I recently ran into a scenario where our cucumber tests would fail on our build server if tests within other jobs were being ran simultaneously. About halfway through, a handful of tests would consistently with the error:
An operation on a socket could not be performed because the system lacked sufficient buffer space or because a queue was full. - connect(2) (Errno::ENOBUFS)
Cucumber uses Chromedriver to communicate with Chrome over TCP/IP, using a wide range of temporary ports on the server. If your run a
netstat -a from the command line while it’s running, you can see the port allocation. After a request completes, the socket is ready to close and goes into
TIME_WAIT status. This gives any trailing packets time to catch up before the door closes. By default, the server keeps the socket in
TIME_WAIT status for 4 minutes and is unavailable for reuse during that time.
We had enough tests running in parallel that it was exhausting the available ports after 15 minutes. Our solution was to reduce the amount of time the server kept ports in
TIME_WAIT status down to 30 seconds, which is more than reasonable for our build server.
To do this, open regedit and add a new DWORD entry named TcpTimedWaitDelay in the HKLM\SYSTEM\CurrentControlSet\Services\Tcpip\Parameters folder – giving it a DECIMAL value of 30. (Will require a reboot.)
Hopefully this saves someone else some time!