Skip to content

Fix connector fd leak and ArrayIndexOutOfBoundsException in query parsing#25

Open
29shivam wants to merge 1 commit into
b:masterfrom
29shivam:fix/consumer-fd-leak-and-query-parse
Open

Fix connector fd leak and ArrayIndexOutOfBoundsException in query parsing#25
29shivam wants to merge 1 commit into
b:masterfrom
29shivam:fix/consumer-fd-leak-and-query-parse

Conversation

@29shivam

Copy link
Copy Markdown

Summary

Fixes two bugs:

1. File descriptor leak in KafkaConsumer.stop() (closes #9)

connector.commitOffsets() is called before connector.shutdown() with no exception handling between them. If commitOffsets() throws a RuntimeException, shutdown() is never reached and the ZooKeeper/Kafka sockets held by the ConsumerConnector stay 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 InterruptedException in a try-finally so connector.shutdown() is guaranteed to run.

2. ArrayIndexOutOfBoundsException in getQueryMap() on value-less query params

param.split("=") followed by nameval[1] crashes when a query parameter has no value (e.g. ?topics=). Java's split drops trailing empty strings, producing a one-element array and throwing ArrayIndexOutOfBoundsException. This also incorrectly splits base64-encoded values that contain = padding.

Fix: use split("=", 2) with a nameval.length == 2 guard.

Test plan

  • Connect a client with a value-less query param (?topics=) — should not throw
  • Connect a client with a base64 value containing = — should parse correctly
  • Trigger rapid WebSocket open/close cycles under HAProxy health checks — fd count should remain stable

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>
@29shivam 29shivam force-pushed the fix/consumer-fd-leak-and-query-parse branch from 574c2ee to 43d5cdb Compare June 26, 2026 04:20
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.

possible fd leak

1 participant