Skip to content

[issue #1357][producer] fix: allow multiples callbacks with concurrent producer flushes (async publish) - #1409

Merged
crossoverJie merged 4 commits into
apache:masterfrom
thomas-bousquet:fix/async-producer-concurrent-flushes
Aug 27, 2025
Merged

crossoverJie merged 4 commits into
apache:masterfrom
thomas-bousquet:fix/async-producer-concurrent-flushes

Conversation

@thomas-bousquet

Copy link
Copy Markdown
Contributor

Fixes #1357

Motivation

When flushing concurrently with the same producer, the producer potentially creates a deadlock when the callback is only called once but the client waits for the flush request to be done in all FlushWithCtx().

Modifications

Change the callback function for to a list of callbacks.

Verifying this change

Testcase TestConcurrentFlushInProducer added in the producer test suite.

@thomas-bousquet thomas-bousquet changed the title [issue 1357][producer] fix: allow multiples callbacks with concurrent producer flushes (async publish) [issue #1357][producer] fix: allow multiples callbacks with concurrent producer flushes (async publish) Aug 25, 2025
@crossoverJie
crossoverJie requested a review from Copilot August 26, 2025 03:14

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull Request Overview

This PR fixes a deadlock issue that occurs when multiple concurrent flush operations are performed on the same producer with async publishing. The solution changes the callback mechanism from a single callback to a list of callbacks to ensure all waiting flush requests are properly notified.

  • Change single flush callback to a list of callbacks in pendingItem struct
  • Update flush handling logic to append and iterate through multiple callbacks
  • Add comprehensive test for concurrent flush scenarios

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 2 comments.

File Description
pulsar/producer_partition.go Core fix - changes single flushCallback to flushCallbacks slice and updates callback handling
pulsar/producer_test.go Adds new test TestConcurrentFlushInProducer to validate the fix
pulsaradmin/pkg/admin/subscription_test.go Updates test to use FlushWithCtx instead of deprecated Flush method
pulsar/consumer_test.go Updates tests to use FlushWithCtx instead of deprecated Flush method

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

Comment thread pulsar/producer_test.go Resolved
Comment thread pulsar/producer_test.go Resolved
@thomas-bousquet
thomas-bousquet force-pushed the fix/async-producer-concurrent-flushes branch from c17a338 to c6b5705 Compare August 26, 2025 03:18
@crossoverJie crossoverJie added this to the v0.17.0 milestone Aug 26, 2025

@crossoverJie crossoverJie left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM

Comment thread .github/workflows/ci.yml Resolved

@lhotari lhotari left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

LGTM, thanks for the contribution

@crossoverJie
crossoverJie merged commit 7a9a33c into apache:master Aug 27, 2025
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.

Calling producer.Flush concurrently would hang indefinitely

4 participants