Skip to content

[fix][meta] Fix deadlock causes session notification not to work - #19754

Merged
liangyepianzhou merged 8 commits into
apache:masterfrom
mattisonchao:fix/double/leader-2
Mar 9, 2023
Merged

[fix][meta] Fix deadlock causes session notification not to work#19754
liangyepianzhou merged 8 commits into
apache:masterfrom
mattisonchao:fix/double/leader-2

Conversation

@mattisonchao

@mattisonchao mattisonchao commented Mar 8, 2023

Copy link
Copy Markdown
Member

Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

image

^^ blocked thread

image

^^ executor queue

Modifications

  • Avoid putting the new task to single thread executor causes deadlock.

Verifying this change

  • Make sure that the change passes the CI checks.

Documentation

  • doc-not-needed

@github-actions

github-actions Bot commented Mar 8, 2023

Copy link
Copy Markdown

@mattisonchao Please add the following content to your PR description and select a checkbox:

- [ ] `doc` <!-- Your PR contains doc changes -->
- [ ] `doc-required` <!-- Your PR changes impact docs and you will update later -->
- [ ] `doc-not-needed` <!-- Your PR changes do not impact docs -->
- [ ] `doc-complete` <!-- Docs have been already added -->

@mattisonchao

mattisonchao commented Mar 8, 2023

Copy link
Copy Markdown
Member Author

@lhotari would you mind taking a look? it looks like the problem introduced by #17401

I think it's a critical issue for our users who have enabled session listening.

}).thenCompose(leaderElectionState -> {
// make sure that the cache contains the current leader
// so that getLeaderValueIfPresent works on all brokers
cache.refresh(path);

@mattisonchao mattisonchao Mar 8, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I checked the logic. This method looks changed and no blocking call anymore. /cc @lhotari

@mattisonchao mattisonchao reopened this Mar 8, 2023
cache.refresh(path);
return cache.get(path)
.thenApply(__ -> leaderElectionState);
}, executor);

@mattisonchao mattisonchao Mar 8, 2023

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

We can't use this single thread executor here because session notification method ( handleSessionNotification )also uses this executor to do blocking get. It will cause a deadlock.

@codelipenghui codelipenghui 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.

Nice catch!

And I think it should be a critical bug introduced to 2.8.5, 2.9.4, 2.10.3, 2.11.1.
IMO, we should notice it in the mailing list to clarify it. It will help users decide
whether to upgrade to 2.8.5, 2.9.4, 2.10.3, or 2.11.0. Or whether to downgrade
to 2.8.4, 2.9.3, 2.10.2.

As I know, 2.9.5, 2.10.4, and 2.11.1 is in the release process. We should ship this
fix to the subsequent patch releases. For 2.8.5, maybe we also need to plan 2.8.6.

For the solution that the PR introduced. Yes, I think it can fix the issue.
IMO, instead of changing the thread, can we change the handleSessionNotification
method to an async method? I mean just to avoid any cases that block the executor
specified to the LeaderElectionImpl. I think it is not expected, right?

A possible solution is when the session event arrives. We can just put the event
in a queue and process it asynchronously. Like processing the next event if the
future of the current event is done. So that we don't need to block any thread.

@mattisonchao

mattisonchao commented Mar 9, 2023

Copy link
Copy Markdown
Member Author

For the solution that the PR introduced. Yes, I think it can fix the issue.
IMO, instead of changing the thread, can we change the handleSessionNotification
method to an async method? I mean just to avoid any cases that block the executor
specified to the LeaderElectionImpl. I think it is not expected, right?

Yes, that is what I thought, which may change much logic here. The async changes are just an improvement, not a bug fix. We can do it in the next PR. since the more complex changes will need more time to review.

We can just revert the part of #17401 to cherry-pick it to previous branches.

WDYT? @codelipenghui

@codelipenghui

Copy link
Copy Markdown
Contributor

Yes, that is what I thought, which may change much logic here. The async changes are just an improvement, not a bug fix. We can do it in the next PR. since the more complex changes will need more time to review.

@mattisonchao Ok, sounds good to me. Let's revert the problem change to the old version, then find a better solution.

@poorbarcode poorbarcode 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.

LGTM

@mattisonchao mattisonchao changed the title [fix][meta] Fix deadlock causes session notification is not to work [fix][meta] Fix deadlock causes session notification not to work Mar 9, 2023
@liangyepianzhou
liangyepianzhou merged commit cbd799f into apache:master Mar 9, 2023
@lordcheng10

Copy link
Copy Markdown
Contributor

nice catch!

@mattisonchao mattisonchao added release/2.10.4 release/blocker Indicate the PR or issue that should block the release until it gets resolved release/2.9.5 and removed release/2.10.5 release/2.9.6 labels Mar 9, 2023
coderzc pushed a commit that referenced this pull request Mar 9, 2023
)

### Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

<img width="1061" alt="image" src="https://user-images.githubusercontent.com/74767115/223670419-c4319f44-f1e1-4361-8c79-04c7f0dabe3c.png">
^^ blocked thread

<img width="949" alt="image" src="https://user-images.githubusercontent.com/74767115/223672000-fb4ce22c-6a45-4cb6-9d23-c36e3afbc93a.png">

^^ executor queue

### Modifications

- Avoid putting the new task to single thread executor causes deadlock.

(cherry picked from commit cbd799f)
@coderzc coderzc added the cherry-picked/branch-2.9 Archived: 2.9 is end of life label Mar 9, 2023
@mattisonchao
mattisonchao deleted the fix/double/leader-2 branch March 9, 2023 03:49
liangyepianzhou pushed a commit that referenced this pull request Mar 9, 2023
)

### Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

<img width="1061" alt="image" src="https://user-images.githubusercontent.com/74767115/223670419-c4319f44-f1e1-4361-8c79-04c7f0dabe3c.png">
^^ blocked thread

<img width="949" alt="image" src="https://user-images.githubusercontent.com/74767115/223672000-fb4ce22c-6a45-4cb6-9d23-c36e3afbc93a.png">

^^ executor queue

### Modifications

- Avoid putting the new task to single thread executor causes deadlock.

(cherry picked from commit cbd799f)
liangyepianzhou added a commit that referenced this pull request Mar 10, 2023
…ot to work (#19754) (#19768)

Co-authored-by: Qiang Zhao <mattisonchao@apache.org>
Master #19754
### Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

<img width="1061" alt="image" src="https://user-images.githubusercontent.com/74767115/223670419-c4319f44-f1e1-4361-8c79-04c7f0dabe3c.png"> ^^ blocked thread

<img width="949" alt="image" src="https://user-images.githubusercontent.com/74767115/223672000-fb4ce22c-6a45-4cb6-9d23-c36e3afbc93a.png">

^^ executor queue

### Modifications

- Avoid putting the new task to single thread executor causes deadlock.

(cherry picked from commit cbd799f)
Technoboy- pushed a commit that referenced this pull request Mar 10, 2023
)

### Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

<img width="1061" alt="image" src="https://user-images.githubusercontent.com/74767115/223670419-c4319f44-f1e1-4361-8c79-04c7f0dabe3c.png">
^^ blocked thread

<img width="949" alt="image" src="https://user-images.githubusercontent.com/74767115/223672000-fb4ce22c-6a45-4cb6-9d23-c36e3afbc93a.png">

^^ executor queue


### Modifications

- Avoid putting the new task to single thread executor causes deadlock.
nicoloboschi pushed a commit to datastax/pulsar that referenced this pull request Mar 10, 2023
…ot to work (apache#19754) (apache#19768)

Co-authored-by: Qiang Zhao <mattisonchao@apache.org>
Master apache#19754
### Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

<img width="1061" alt="image" src="https://user-images.githubusercontent.com/74767115/223670419-c4319f44-f1e1-4361-8c79-04c7f0dabe3c.png"> ^^ blocked thread

<img width="949" alt="image" src="https://user-images.githubusercontent.com/74767115/223672000-fb4ce22c-6a45-4cb6-9d23-c36e3afbc93a.png">

^^ executor queue

### Modifications

- Avoid putting the new task to single thread executor causes deadlock.

(cherry picked from commit cbd799f)
(cherry picked from commit 36794d9)
liangyepianzhou pushed a commit to streamnative/pulsar-archived that referenced this pull request Mar 14, 2023
…che#19754)

### Motivation

This is a namespace bundle double-owners problem. We found it in the memory dumps.

The memory dumps show that the notification thread has been blocked for a long time by the leader election deadlock, And many notifications are blocked in the executor queue. This causes we can't to revalidate the locks, and they are still thinking them working well.

For private reasons, I can't share the namespace bundle snapshot, but the blocked thread easily explains it.

<img width="1061" alt="image" src="https://user-images.githubusercontent.com/74767115/223670419-c4319f44-f1e1-4361-8c79-04c7f0dabe3c.png">
^^ blocked thread

<img width="949" alt="image" src="https://user-images.githubusercontent.com/74767115/223672000-fb4ce22c-6a45-4cb6-9d23-c36e3afbc93a.png">

^^ executor queue

### Modifications

- Avoid putting the new task to single thread executor causes deadlock.

(cherry picked from commit cbd799f)
@mattisonchao mattisonchao removed the release/blocker Indicate the PR or issue that should block the release until it gets resolved label Mar 29, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

8 participants