Skip to content

Commit

Permalink
Gracefully handle exceptions thrown when receiving messages from AWS …
Browse files Browse the repository at this point in the history
…SNS+SQS
  • Loading branch information
kalaspuff committed Jan 12, 2018
1 parent 31e71d2 commit 85c1c9a
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions tomodachi/transport/aws_sns_sqs.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ujson
import uuid
import inspect
from botocore.parsers import ResponseParserError
from typing import Any, Dict, Union, Optional, Callable, List, Tuple, Match
try:
from typing import Awaitable
Expand Down Expand Up @@ -486,6 +487,12 @@ async def _callback() -> None:
logging.getLogger('transport.aws_sns_sqs').warning('Unable to receive message from queue [sqs] on AWS ({}) - reconnecting'.format(error_message))
await asyncio.sleep(1)
continue
except ResponseParserError as e:
is_disconnected = True
error_message = 'Unable to parse response: the server was not able to produce a timely response to your request'
logging.getLogger('transport.aws_sns_sqs').warning('Unable to receive message from queue [sqs] on AWS ({}) - reconnecting'.format(error_message))
await asyncio.sleep(1)
continue
except (botocore.exceptions.ClientError, aiohttp.client_exceptions.ClientConnectorError, asyncio.TimeoutError) as e:
error_message = str(e) if not isinstance(e, asyncio.TimeoutError) else 'Network timeout'
if 'AWS.SimpleQueueService.NonExistentQueue' in error_message:
Expand All @@ -506,6 +513,11 @@ async def _callback() -> None:
logging.getLogger('transport.aws_sns_sqs').warning('Unable to receive message from queue [sqs] on AWS ({})'.format(error_message))
await asyncio.sleep(1)
continue
except Exception as e:
error_message = str(e)
logging.getLogger('transport.aws_sns_sqs').warning('Unexpected error while receiving message from queue [sqs] on AWS ({})'.format(error_message))
await asyncio.sleep(1)
continue

messages = response.get('Messages', [])
if messages:
Expand Down

0 comments on commit 85c1c9a

Please sign in to comment.