Skip to content

Fix FanoutRecordsPublisher restartFrom behavior at SHARD_END - #1744

Merged
lucienlu-aws merged 4 commits into
awslabs:masterfrom
lucienlu-aws:fanout-restart-fix
May 28, 2026
Merged

lucienlu-aws merged 4 commits into
awslabs:masterfrom
lucienlu-aws:fanout-restart-fix

Conversation

@lucienlu-aws

@lucienlu-aws lucienlu-aws commented May 20, 2026 •

Copy link
Copy Markdown
Contributor

Issue #, if available:

Description of changes:
If the FanoutRecordsPublisher reaches the last SubscribeToShardEvent, the continuationSequenceNumber returned by the service is null. This causes an issue if the publisher runs into an error and the ShardConsumerSubscriber calls restartFrom for the lastAccepted event (ref). The FanoutRecordsPublisher would set the continuationSequenceNumber to null (ref)causing the subscribeToShard requests to continuously fail where the only remediation would be to force the worker to drop the lease.

This commit updates the FanoutRecordsPublisher to handle the SHARD_END event case. If the publisher restartsFrom SHARD_END, it will instead call subscribeToShard with LATEST, which will return the last SHARD_END event from the service and continue the normal SHARD_END tasks through the ShardConsumer and RecordProcessor.

By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

synchronized (lockObject) {
// Clear the delivery queue so that any stale entries from previous subscription are discarded.
resetRecordsDeliveryStateOnSubscriptionOnInit();
log.info("ShardId: {}, consumrArn: {}", shardId, consumerArn);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might want to remove noisy log

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Was left over from testing I think, thanks

Comment on lines +162 to +164
ExtendedSequenceNumber continuationSeqNum =
((FanoutRecordsRetrieved) recordsRetrieved).continuationSequenceNumber();
currentSequenceNumber = continuationSeqNum;

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: just assign to currentSequenceNumber directly

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Updated

@Accessors(fluent = true)
@Data
static class FanoutRecordsRetrieved implements RecordsRetrieved {
public static class FanoutRecordsRetrieved implements RecordsRetrieved {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

do we need the scope change?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, put back to protected scope now

@lucienlu-aws
lucienlu-aws merged commit b1aa9dc into awslabs:master May 28, 2026
7 checks passed
@lucienlu-aws
lucienlu-aws deleted the fanout-restart-fix branch May 28, 2026 20:10
vincentvilo-aws pushed a commit to vincentvilo-aws/amazon-kinesis-client that referenced this pull request Jun 17, 2026
…#1744)

* Fix FanoutRecordsPublisher restartFrom behavior at SHARD_END

This branch was previously deployed

1 inactive deployment
manual-approval — 50dc13b9 Deployed May 28, 2026 by lucienlu-aws via wait-for-approval #201
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants