Prevent typeerror when committing offsets for a topic before initialization #1235
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I cannot reproduce this myself, but I have seen a service somehow triggering this in production. I think it's triggered somehow when trying to commit offsets for a topic before the consumer has gone through the fetch loop, or maybe something to do with them using a different consumer instance to commit than they are using to consume. This application is basically storing references to consumers in a lookup table, and replacing the consumers whenever there's any error, which means that they might be calling
consumer.commitOffsets
while the consumer is somewhere in the middle of joining the group or in the middle of shutting down etc. Clearly they shouldn't do that, but any which way KafkaJS shouldn't throw a TypeError here.The code is assuming that
committedOffsets()[topic]
will always return an object, but in some weird circumstance that's not the case, so it throws a TypeError from trying to doObject.assign(undefined, offsets)
.