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

Fixed double mutex acquisition deadlock when recreating UDP session #372

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

alamar
Copy link

@alamar alamar commented Feb 11, 2025

minor: Opportunistically clean-up stale route rule in outline-cli
closes #342

Copy link

google-cla bot commented Feb 11, 2025

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

Copy link
Contributor

@jyyi1 jyyi1 left a comment

Choose a reason for hiding this comment

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

Thanks a lot for the fixing. We are experiencing similar issues on other products as well, this is very helpful! I have added some comments, please take a look.

x/examples/outline-cli/routing_linux.go Outdated Show resolved Hide resolved
x/examples/outline-cli/routing_linux.go Show resolved Hide resolved
@@ -55,13 +55,15 @@ func (h *udpHandler) ReceiveTo(tunConn lwip.UDPConn, data []byte, destAddr *net.

h.mu.Lock()
reqSender, ok := h.senders[laddr]
h.mu.Unlock()
if !ok {
if reqSender, err = h.newSession(tunConn); err != nil {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest adding a h.mu.Unlock() before returning. The goal is to protect both h.senders[laddr] read and h.senders[laddr] = reqSender write.

Copy link
Author

Choose a reason for hiding this comment

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

Unfortunately, this is not possible since newSession will do h.mu.Lock() as well, so if it's not unlocked by then, it will always deadlock. As I understand, this execution path will always cause deadlock in the current code base.

I understand there may be an issue regarding access of h.senders[laddr], but fixing it requires uprooting way more code that I understand at the moment. So I suggest to fix the hard deadlock issue now with minimal change - if there are any issues with UDP sessions access synchronization in the future, they may be taken care of separately. After all, this piece of code was essentially a dead end so there may be more bugs there.

Copy link
Author

Choose a reason for hiding this comment

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

Perhaps I didn't understand you well and perhaps I didn't explain the issue well, so it's not possible to always do all h.senders[laddr] access inside the same mutex as they are interleaved with newSession() sometimes which requires mutex to be unlocked first.

minor: Opportunistically clean-up stale route rule in outline-cli
closes Jigsaw-Code#342
@alamar
Copy link
Author

alamar commented Feb 15, 2025

@jyyi1 please re-review - I've addressed formatting issue and replied on comments.

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.

Tunnel fails to close after Linux system resumes from sleep
3 participants