-
Notifications
You must be signed in to change notification settings - Fork 191
Replace tokio mutex with std mutex #1866
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
Conversation
@@ -53,12 +53,12 @@ impl ReceiverOutput for QueueForwarder { | |||
} | |||
|
|||
async fn handle(&self, request: ForwardRequest) -> Result<(), BoxError> { | |||
let mut sender = self.sender.lock().await; | |||
let mut sender = self.sender.lock().unwrap(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This seems wrong? Won't be block the async thread every time we wait on a lock?
Also the unwrap feels like a code smell.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, the sender is by necessity held over await points so we must not use a std Mutex for it.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
acf5518
to
97c16f8
Compare
b9f986c
to
16fc322
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
All of the changes outside of the test code still look wrong to me. I'm pretty sure we need the async mutex in all of those cases. And for the test code, it doesn't seem all that useful to switch either.
I will trigger CI to run again to make sure, but unless you have a specific reason to believe there is a worthwhile change here, I'd encourage you to close this PR and I'll close the associated issue since it doesn't look like there was anything of substance there really.
Hii @svix-jplatte thanks for review i am closing this PR. please close the associated issue too. |
Motivation
std::sync::Mutex
is generally more efficient when the critical sections are short and contention is low, as it avoids the overhead of async machinery.std::sync::Mutex
when:Fixes #1062
Solution
The solution involves:
tokio::sync::Mutex
withstd::sync::Mutex
throughout the codebaseThanks for reviewing it let me know if any changes required