Fix connector fd leak and ArrayIndexOutOfBoundsException in query parsing#25
Open
29shivam wants to merge 1 commit into
Open
Fix connector fd leak and ArrayIndexOutOfBoundsException in query parsing#2529shivam wants to merge 1 commit into
29shivam wants to merge 1 commit into
Conversation
KafkaConsumer.stop() used a straight-line call sequence where an exception from commitOffsets() would skip connector.shutdown(), leaving ZooKeeper/Kafka sockets open indefinitely (issue b#9). Wrap with try-finally so shutdown() is always called. getQueryMap() called split("=") and indexed [1] unconditionally. Java drops trailing empty strings, so "key=" yields a one-element array and throws ArrayIndexOutOfBoundsException. Switch to split("=", 2) with a length guard; the limit-2 form also correctly handles base64 values that contain '=' characters. Signed-off-by: 29shivam <shivamsingh6126@gmail.com>
574c2ee to
43d5cdb
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes two bugs:
1. File descriptor leak in
KafkaConsumer.stop()(closes #9)connector.commitOffsets()is called beforeconnector.shutdown()with no exception handling between them. IfcommitOffsets()throws aRuntimeException,shutdown()is never reached and the ZooKeeper/Kafka sockets held by theConsumerConnectorstay open indefinitely. Under load (e.g. HAProxy health checks repeatedly opening/closing connections), these accumulate until the process hits the OS ulimit.Fix: wrap the try/catch for
InterruptedExceptionin a try-finally soconnector.shutdown()is guaranteed to run.2.
ArrayIndexOutOfBoundsExceptioningetQueryMap()on value-less query paramsparam.split("=")followed bynameval[1]crashes when a query parameter has no value (e.g.?topics=). Java'ssplitdrops trailing empty strings, producing a one-element array and throwingArrayIndexOutOfBoundsException. This also incorrectly splits base64-encoded values that contain=padding.Fix: use
split("=", 2)with anameval.length == 2guard.Test plan
?topics=) — should not throw=— should parse correctly