conn: fix Receive blocking Send#291
Open
nickgarlis wants to merge 1 commit intomdlayher:mainfrom
Open
Conversation
In mdlayher#265, Receive was changed from RLock to Lock to serialize concurrent Receive calls. Since Send uses RLock, it blocks for as long as Receive holds the exclusive lock. When Receive is blocking in recvmsg waiting for kernel data, Send is blocked too. This causes a deadlock in patterns like NFQUEUE, where one can goroutine read packets while another sends verdicts concurrently. Fix by introducing a separate receiveMu that serializes concurrent Receive calls without holding mu exclusively, keeping Send and Receive concurrency compatible. Fixes: mdlayher#288
Collaborator
Author
|
@florianl Do you mind having a look ? |
florianl
reviewed
May 6, 2026
Contributor
florianl
left a comment
There was a problem hiding this comment.
How about a test like https://gist.github.com/florianl/13bedaf2bb26bb3c0a0ce52df9e229fb that does not depend on time.Sleep()?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In #265, Receive was changed from RLock to Lock to serialize concurrent Receive calls. Since Send uses RLock, it blocks for as long as Receive holds the exclusive lock. When Receive is blocking in recvmsg waiting for kernel data, Send is blocked too. This causes a deadlock in patterns like NFQUEUE, where one can goroutine read packets while another sends verdicts concurrently.
Fix by introducing a separate receiveMu that serializes concurrent Receive calls without holding mu exclusively, keeping Send and Receive concurrency compatible.
Fixes: #288