Commit cb462b06 authored by Michael Hanselmann's avatar Michael Hanselmann
Browse files

Handle EAGAIN in LUXI client



If too many clients try to connect to the master at the same time, some of
them might fail if the master doesn't accept the connections fast enough.
Signed-off-by: default avatarMichael Hanselmann <hansmi@google.com>
Reviewed-by: default avatarIustin Pop <iustin@google.com>
parent 632fb7ec
...@@ -37,6 +37,7 @@ import errno ...@@ -37,6 +37,7 @@ import errno
from ganeti import serializer from ganeti import serializer
from ganeti import constants from ganeti import constants
from ganeti import errors from ganeti import errors
from ganeti import utils
KEY_METHOD = 'method' KEY_METHOD = 'method'
...@@ -156,15 +157,14 @@ class Transport: ...@@ -156,15 +157,14 @@ class Transport:
try: try:
self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) self.socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
self.socket.settimeout(self._ctimeout)
# Try to connect
try: try:
self.socket.connect(address) utils.Retry(self._Connect, 1.0, self._ctimeout,
except socket.timeout, err: args=(self.socket, address, self._ctimeout))
raise TimeoutError("Connect timed out: %s" % str(err)) except utils.RetryTimeout:
except socket.error, err: raise TimeoutError("Connect timed out")
if err.args[0] in (errno.ENOENT, errno.ECONNREFUSED):
raise NoMasterError(address)
raise
self.socket.settimeout(self._rwtimeout) self.socket.settimeout(self._rwtimeout)
except (socket.error, NoMasterError): except (socket.error, NoMasterError):
if self.socket is not None: if self.socket is not None:
...@@ -172,6 +172,21 @@ class Transport: ...@@ -172,6 +172,21 @@ class Transport:
self.socket = None self.socket = None
raise raise
@staticmethod
def _Connect(sock, address, timeout):
sock.settimeout(timeout)
try:
sock.connect(address)
except socket.timeout, err:
raise TimeoutError("Connect timed out: %s" % str(err))
except socket.error, err:
if err.args[0] in (errno.ENOENT, errno.ECONNREFUSED):
raise NoMasterError(address)
if err.args[0] == errno.EAGAIN:
# Server's socket backlog is full at the moment
raise utils.RetryAgain()
raise
def _CheckSocket(self): def _CheckSocket(self):
"""Make sure we are connected. """Make sure we are connected.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment