mirror of
https://github.com/cisagov/manage.get.gov.git
synced 2025-08-12 20:49:41 +02:00
Merge pull request #1447 from cisagov/es/1415-epp-retry
#1415 Retry EPP connection pool on Transport Error
This commit is contained in:
commit
6f1642eaf2
2 changed files with 10 additions and 4 deletions
|
@ -17,7 +17,7 @@ except ImportError:
|
||||||
from django.conf import settings
|
from django.conf import settings
|
||||||
|
|
||||||
from .cert import Cert, Key
|
from .cert import Cert, Key
|
||||||
from .errors import LoginError, RegistryError
|
from .errors import ErrorCode, LoginError, RegistryError
|
||||||
from .socket import Socket
|
from .socket import Socket
|
||||||
from .utility.pool import EPPConnectionPool
|
from .utility.pool import EPPConnectionPool
|
||||||
|
|
||||||
|
@ -115,7 +115,7 @@ class EPPLibWrapper:
|
||||||
except TransportError as err:
|
except TransportError as err:
|
||||||
message = f"{cmd_type} failed to execute due to a connection error."
|
message = f"{cmd_type} failed to execute due to a connection error."
|
||||||
logger.error(f"{message} Error: {err}", exc_info=True)
|
logger.error(f"{message} Error: {err}", exc_info=True)
|
||||||
raise RegistryError(message) from err
|
raise RegistryError(message, code=ErrorCode.TRANSPORT_ERROR) from err
|
||||||
except LoginError as err:
|
except LoginError as err:
|
||||||
# For linter due to it not liking this line length
|
# For linter due to it not liking this line length
|
||||||
text = "failed to execute due to a registry login error."
|
text = "failed to execute due to a registry login error."
|
||||||
|
@ -163,7 +163,8 @@ class EPPLibWrapper:
|
||||||
try:
|
try:
|
||||||
return self._send(command)
|
return self._send(command)
|
||||||
except RegistryError as err:
|
except RegistryError as err:
|
||||||
if err.should_retry() and counter < 3:
|
if counter < 3 and (err.should_retry() or err.is_transport_error()):
|
||||||
|
logger.info(f"Retrying transport error. Attempt #{counter+1} of 3.")
|
||||||
counter += 1
|
counter += 1
|
||||||
sleep((counter * 50) / 1000) # sleep 50 ms to 150 ms
|
sleep((counter * 50) / 1000) # sleep 50 ms to 150 ms
|
||||||
else: # don't try again
|
else: # don't try again
|
||||||
|
|
|
@ -4,13 +4,15 @@ from enum import IntEnum
|
||||||
class ErrorCode(IntEnum):
|
class ErrorCode(IntEnum):
|
||||||
"""
|
"""
|
||||||
Overview of registry response codes from RFC 5730. See RFC 5730 for full text.
|
Overview of registry response codes from RFC 5730. See RFC 5730 for full text.
|
||||||
|
- 0 System connection error
|
||||||
- 1000 - 1500 Success
|
- 1000 - 1500 Success
|
||||||
- 2000 - 2308 Registrar did something silly
|
- 2000 - 2308 Registrar did something silly
|
||||||
- 2400 - 2500 Registry did something silly
|
- 2400 - 2500 Registry did something silly
|
||||||
- 2501 - 2502 Something malicious or abusive may have occurred
|
- 2501 - 2502 Something malicious or abusive may have occurred
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
TRANSPORT_ERROR = 0
|
||||||
|
|
||||||
COMMAND_COMPLETED_SUCCESSFULLY = 1000
|
COMMAND_COMPLETED_SUCCESSFULLY = 1000
|
||||||
COMMAND_COMPLETED_SUCCESSFULLY_ACTION_PENDING = 1001
|
COMMAND_COMPLETED_SUCCESSFULLY_ACTION_PENDING = 1001
|
||||||
COMMAND_COMPLETED_SUCCESSFULLY_NO_MESSAGES = 1300
|
COMMAND_COMPLETED_SUCCESSFULLY_NO_MESSAGES = 1300
|
||||||
|
@ -67,6 +69,9 @@ class RegistryError(Exception):
|
||||||
def should_retry(self):
|
def should_retry(self):
|
||||||
return self.code == ErrorCode.COMMAND_FAILED
|
return self.code == ErrorCode.COMMAND_FAILED
|
||||||
|
|
||||||
|
def is_transport_error(self):
|
||||||
|
return self.code == ErrorCode.TRANSPORT_ERROR
|
||||||
|
|
||||||
# connection errors have error code of None and [Errno 99] in the err message
|
# connection errors have error code of None and [Errno 99] in the err message
|
||||||
def is_connection_error(self):
|
def is_connection_error(self):
|
||||||
return self.code is None
|
return self.code is None
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue