-
-
Notifications
You must be signed in to change notification settings - Fork 4.2k
[ESM] Handle DynamoDB-local Invalid ShardID exception #12036
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
LocalStack Community integration with Pro 2 files ± 0 2 suites ±0 1h 30m 23s ⏱️ - 20m 10s Results for commit e02a1af. ± Comparison against base commit 235a06a. This pull request removes 950 tests.
♻️ This comment has been updated with latest results. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks a lot for tackling this! 🙏
I'll probably open a follow up soon with the TrimmedDataAccessException
exception sometimes raised by DynamoDB-local and also considered to be a bug.
I think this is a safe fix, and if anything goes wrong with Dynamodb-local, it will also flood the logs, so we should be good to go. Hopefully in the future we can rework the sharding behavior!
except self.source_client.exceptions.ExpiredIteratorException as e: | ||
except ( | ||
self.source_client.exceptions.ExpiredIteratorException, | ||
self.source_client.exceptions.TrimmedDataAccessException, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, that's nice, I thought we'd need to do string matching again, but both dynamodbstreams
and the kinesis
clients implements the TrimmedDataAccessException
? That's practical 😄
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Kinesis doesn't raise this ://// will re-implement
localstack-core/localstack/services/lambda_/event_source_mapping/pollers/stream_poller.py
Outdated
Show resolved
Hide resolved
def get_records(self, shard_iterator: str) -> dict: | ||
try: | ||
return super().get_records(shard_iterator) | ||
except self.source_client.exceptions.TrimmedDataAccessException as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is not going to be caught because self.source_client.exceptions.TrimmedDataAccessException
is a subclass from ClientError
, and the parent class get_records
is already catching that, and if not a "recognized" exception, raised PipeInternalError from e
. Not sure if we can catch that somehow? Ugh, sorry for this one... 😓
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I guess we could try to catch PipeInternalError
, verify if it is raised from the exception we want (not even sure how to do that 👀 ) and if not, re-raise? Not great... thanks, DynamoDB-local 😅
Maybe it'd be easier to do a string matching in the parent get_records
like Invalid ShardId in ShardIterator
but matching TrimmedDataAccessException
?
@@ -264,7 +264,7 @@ def get_records(self, shard_iterator: str) -> dict: | |||
) | |||
return get_records_response | |||
# TODO: test iterator expired with conditional error scenario (requires failure destinations) | |||
except self.source_client.exceptions.ExpiredIteratorException as e: | |||
except self.source_client.exceptions.ExpiredIteratorExceptionas as e: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except self.source_client.exceptions.ExpiredIteratorExceptionas as e: | |
except self.source_client.exceptions.ExpiredIteratorException as e: |
451256b
to
ef48cb4
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM! Thanks a lot really for adding the TrimmedDataAccessException
too 🙇
e, | ||
) | ||
raise CustomerInvocationError from e | ||
elif "TrimmedDataAccessException" in str(e): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you so much for adding this! 🙏 I'll tell the users next week about it for them to confirm to us it solves the issue and they don't need to run the command manually anymore! Thank you very much for going the extra mile here 🙇
Motivation
Doing a
GetRecords
operation against DynamoDB-local can raise an (undocumented)Invalid ShardId in ShardIterator
exception. Since we poll a stream in ESM, encountering this sharding issue should necessitate a re-initialise of the shards we are polling.Changes
Invalid ShardId in ShardIterator
, and trigger a re-sharding if encountered.