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

Unlock the write lock of the UnAckedMessageTracker before call redeliverUnacknowledgedMessages #10768

Merged
merged 1 commit into from
Jun 1, 2021

Conversation

codelipenghui
Copy link
Contributor

@codelipenghui codelipenghui commented Jun 1, 2021

Fixes #10767

Motivation

The deadlock will happen in following steps:

  1. The client internal thread got the consumer instance lock when call internalBatchReceiveAsync
  2. The timer thread got the write lock of the UnAckedMessageTracker and then waiting on the consumer instance lock when call redeliverUnacknowledgedMessages
  3. The client internal thread try to get the write lock of the UnAckedMessageTracker when adding unacked messages

The deadlock happens since the timer thread hold the write lock of the UnAckedMessageTracker

The fix is to ensure the timer thread unlock the write lock before call redeliverUnacknowledgedMessages

…verUnacknowledgedMessages

The deadlock will happen in following steps:

1. The client internal thread got the consumer instance lock when call internalBatchReceiveAsync
2. The timer thread got the write lock of the UnAckedMessageTracker and then waiting on the consumer instance lock when call redeliverUnacknowledgedMessages
3. The client internal thread try to get the write lock of the UnAckedMessageTracker when adding unacked messages

The deadlock happens.

The fix is ensure the timer thread unlock the write lock before call redeliverUnacknowledgedMessages
@codelipenghui codelipenghui self-assigned this Jun 1, 2021
@codelipenghui codelipenghui added this to the 2.8.0 milestone Jun 1, 2021
@codelipenghui codelipenghui added release/blocker Indicate the PR or issue that should block the release until it gets resolved area/client type/bug The PR fixed a bug or issue reported a bug labels Jun 1, 2021
Copy link
Member

@lhotari lhotari left a comment

Choose a reason for hiding this comment

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

LGTM

@315157973
Copy link
Contributor

Write lock is reentrant, why is it deadlock? Please correct me if I am wrong.

Copy link
Contributor

@eolivelli eolivelli left a comment

Choose a reason for hiding this comment

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

LGTM

@codelipenghui
Copy link
Contributor Author

@315157973 As described in the PR description, they are from different threads, one is the client internal thread, one is timer thread.

Copy link
Contributor

@315157973 315157973 left a comment

Choose a reason for hiding this comment

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

Thanks for your explanation

@eolivelli eolivelli merged commit c4ee288 into apache:master Jun 1, 2021
@codelipenghui codelipenghui deleted the penghui/fix-10767 branch June 1, 2021 14:16
yangl pushed a commit to yangl/pulsar that referenced this pull request Jun 23, 2021
…verUnacknowledgedMessages (apache#10768)

The deadlock will happen in following steps:

1. The client internal thread got the consumer instance lock when call internalBatchReceiveAsync
2. The timer thread got the write lock of the UnAckedMessageTracker and then waiting on the consumer instance lock when call redeliverUnacknowledgedMessages
3. The client internal thread try to get the write lock of the UnAckedMessageTracker when adding unacked messages

The deadlock happens.

The fix is ensure the timer thread unlock the write lock before call redeliverUnacknowledgedMessages
bharanic-dev pushed a commit to bharanic-dev/pulsar that referenced this pull request Mar 18, 2022
…verUnacknowledgedMessages (apache#10768)

The deadlock will happen in following steps:

1. The client internal thread got the consumer instance lock when call internalBatchReceiveAsync
2. The timer thread got the write lock of the UnAckedMessageTracker and then waiting on the consumer instance lock when call redeliverUnacknowledgedMessages
3. The client internal thread try to get the write lock of the UnAckedMessageTracker when adding unacked messages

The deadlock happens.

The fix is ensure the timer thread unlock the write lock before call redeliverUnacknowledgedMessages
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/client release/blocker Indicate the PR or issue that should block the release until it gets resolved type/bug The PR fixed a bug or issue reported a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Java client] Deadlock in Pulsar Client when running ConsumerBatchReceiveTest
4 participants