Skip to content
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

Fix a bug when parsing multiple responses #115

Merged
merged 2 commits into from
Aug 18, 2018
Merged

Fix a bug when parsing multiple responses #115

merged 2 commits into from
Aug 18, 2018

Conversation

bowendeng
Copy link

The previous implementation was assuming that the rawData only contains the bytes of a single response. This could cause response loss when mutiple reponses are concatenated into one rawData.

@tulios
Copy link
Owner

tulios commented Aug 17, 2018

Thanks for the PR @bwdeng, have you faced this problem while using the library? We have been using KafkaJS for a while and I haven't seen this behavior.

@tulios tulios self-requested a review August 17, 2018 10:37
// The full payload is loaded, erase the temporary buffer
this.buffer = Buffer.alloc(0)
if (this.authHandlers) {
return this.authHandlers.onSuccess(data.slice(0, this.offset + byteLength))
Copy link
Owner

Choose a reason for hiding this comment

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

byteLength isn't defined, this is breaking the tests

Copy link
Author

Choose a reason for hiding this comment

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

good catch! copy-paste bug...

const correlationId = decoder.readInt32()
const payload = decoder.readAll()
const entry = this.pendingQueue[correlationId]
delete this.pendingQueue[correlationId]
Copy link
Owner

Choose a reason for hiding this comment

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

I wonder if we should remove the previous data from the buffer, I fear to end up leaking memory.

Copy link
Author

@bowendeng bowendeng Aug 17, 2018

Choose a reason for hiding this comment

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

I think we are okey, since the buffer is reset using decoder.readAll() which only copies (not slicing) the rest of the data. So the original buffer could be collected by GC once the response gets consumed.

@bowendeng
Copy link
Author

@tulios It's more likely to happen if multiple requests were sent currently. We were facing a problem when starting a new consumer group. Sometimes, it causes the response of OffsetCommit got lost during offset resetting, causing consumer stuck on initialization.

@tulios
Copy link
Owner

tulios commented Aug 18, 2018

@bwdeng the code makes sense, I just wanted to confirm. I want to rename some things (like data.slice(0, Decoder.int32Size() + expectedResponseSize)), but I can do it later.

Thanks again!

@tulios tulios merged commit ade12dd into tulios:master Aug 18, 2018
@tulios
Copy link
Owner

tulios commented Aug 20, 2018

@bwdeng Thanks again, I'm releasing v1.3.1 with this fix.

o/

@bowendeng bowendeng deleted the fix-mutiple-responses-parsing branch August 20, 2018 13:51
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.

None yet

2 participants