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 a deadlock in Session.Close() during control connection reconnect #1688

Merged
merged 1 commit into from
Apr 11, 2023

Conversation

martin-sucha
Copy link
Contributor

We switched from separate mutex for closing to sessionStateMu in 312a614.
This change introduced a deadlock.

We don't need to hold the mutex for the whole duration of Close(), we only need to update the status atomically.
Previously IsClosed() returned true only after all closing is done (because of the deferred unlock).
We can emulate that by setting isClosed at the end of Close(). We need a new variable to ensure that Close() is only executed once.

Fixes #1687

@joao-r-reis
Copy link
Contributor

I added the test mentioned in #1687 to this branch (locally), ran it and it passed multiple times. It consistently gets stuck when I run it in master so this seems to fix the issue.

We switched from separate mutex for closing to sessionStateMu in
312a614.
This change introduced a deadlock.

We don't need to hold the mutex for the whole duration of Close(),
we only need to update the status atomically.
Previously IsClosed() returned true only after all closing is done
(because of the deferred unlock).
We can emulate that by setting isClosed at the end of Close().
We need a new variable to ensure that Close() is only executed once.

Fixes apache#1687
@martin-sucha
Copy link
Contributor Author

Thanks for checking! I've noticed missing unlock in the return branch, so I added it.

@martin-sucha martin-sucha merged commit b8c4e16 into apache:master Apr 11, 2023
martin-sucha added a commit that referenced this pull request Apr 11, 2023
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.

Deadlock when calling Session.Close() while control connection is reconnecting
2 participants