Skip to content

Release Kafka sink lock on early return and failure - #7231

Open
ashwinhs wants to merge 1 commit into
opensearch-project:mainfrom
ashwinhs:fix/kafka-sink-lock-release
Open

ashwinhs wants to merge 1 commit into
opensearch-project:mainfrom
ashwinhs:fix/kafka-sink-lock-release

Conversation

@ashwinhs

@ashwinhs ashwinhs commented Nov 1, 2026

Copy link
Copy Markdown

Description

KafkaSink.doOutput could return with the lock still held, on empty records or when setup failed. The next call from another thread would then block forever.

Moved the empty check before the lock and the unlock into finally.

Issues Resolved

Part of #7133. This fixes the lock only, not the prepareTopicAndSchema() call.

Check List

  • New functionality includes testing.
  • New functionality has a documentation issue. Please link to it in this PR.
    • New functionality has javadoc added
  • Commits are signed with a real name per the DCO

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.
For more information on following Developer Certificate of Origin and signing off your commits, please check here.

Signed-off-by: Ashwin Somasundara <ashwin.somasundara@gmail.com>
@github-actions

github-actions Bot commented Nov 1, 2026

Copy link
Copy Markdown

PR Reviewer Guide 🔍

Here are some key observations to aid the review process:

🧪 PR contains tests
🔒 No security concerns identified
✅ No TODO sections
🔀 No multiple PR themes
⚡ No major issues detected

assertThat(getLock(objectUnderTest).isLocked(), equalTo(false));
}

private ReentrantLock getLock(final KafkaSink kafkaSink) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Thanks @ashwinhs, the fix looks good. A small thought: could the tests check behavior instead of reading the lock field? For example, after an empty or failing doOutput, a doOutput from another thread should still finish. That way the tests do not depend on a private field name.

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