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

fix:deadlock when reentrant exclusive lock #2905 #2879 #2961

Merged
merged 3 commits into from
Sep 13, 2024

Conversation

Roiocam
Copy link
Contributor

@Roiocam Roiocam commented Aug 16, 2024

Motivation

Resolves: #2905 #2879

Investigation

Both of issues point to this stack trace. I have reproduced this with the sample in #2905.

After some investigation, I figured why, because the thread that holds the shared lock also requires exclusive lock in the same time.(I think it happened on error handling, or the channel was disactive when writer was writing).

      at io.lettuce.core.protocol.Sharedlock.lockWritersExclusive(SharedLock.java:139)
      at io.lettuce.core.protocol.SharedLock.doexclusive(SharedLock.java:114)
      at io.lettuce.core.protocol.DefaultEndpoint.doExclusive(DefaultEndpoint.java:741)

Make sure that:

  • You have read the contribution guidelines.
  • You have created a feature request first to discuss your contribution intent. Please reference the feature request ticket number in the pull request.
  • You applied code formatting rules using the mvn formatter:format target. Don’t submit any formatting related changes.
  • You submit test cases (unit or integration tests) that back your changes.

@Roiocam Roiocam marked this pull request as draft August 16, 2024 06:44
@Roiocam Roiocam marked this pull request as ready for review August 16, 2024 07:58
@Roiocam Roiocam changed the title fix:Deadlock when reentrant exclusive lock #2905 fix:Deadlock when reentrant exclusive lock #2905 #2879 Aug 16, 2024
@Roiocam Roiocam changed the title fix:Deadlock when reentrant exclusive lock #2905 #2879 fix:deadlock when reentrant exclusive lock #2905 #2879 Aug 16, 2024
Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

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

I agree that this is the most likely culprit as the logic seems to assume the same thread could not be a writer at the moment of attempting to do exclusive operations. I have a few minor suggestions for the change.

src/main/java/io/lettuce/core/protocol/SharedLock.java Outdated Show resolved Hide resolved
src/main/java/io/lettuce/core/protocol/SharedLock.java Outdated Show resolved Hide resolved
@tishun tishun added the status: waiting-for-feedback We need additional information before we can continue label Aug 30, 2024
@tishun tishun removed the status: waiting-for-feedback We need additional information before we can continue label Sep 13, 2024
Copy link
Collaborator

@tishun tishun left a comment

Choose a reason for hiding this comment

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

Awesome, thanks for the contibution!

@tishun tishun merged commit bc84058 into redis:main Sep 13, 2024
5 checks passed
@tishun tishun added the type: bug A general bug label Sep 13, 2024
@tishun tishun added this to the 6.5.0.RELEASE milestone Sep 13, 2024
@Roiocam Roiocam deleted the fix-deadlock branch September 26, 2024 08:05
tishun pushed a commit to tishun/lettuce-core that referenced this pull request Nov 1, 2024
…is#2961)

* fix:deadlock when reentrant exclusive lock redis#2905

* confirm won't blocking other thread

* apply suggestions
tishun added a commit that referenced this pull request Nov 1, 2024
* fix:deadlock when reentrant exclusive lock #2905

* confirm won't blocking other thread

* apply suggestions

Co-authored-by: Andy(Jingzhang)Chen <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Deadlock in SharedLock
2 participants