-
Notifications
You must be signed in to change notification settings - Fork 53
Add lock! macro to handle mutex poisoning gracefully #471
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -368,7 +368,7 @@ impl AsyncConnection { | |
| request: ParsedRequest, | ||
| ) -> Pin<Box<dyn Future<Output = Result<Response, Error>> + Send + 'a>> { | ||
| Box::pin(async move { | ||
| let conn = Arc::clone(&*self.0.lock().unwrap()); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ISTM all of the locks for this mutex are only held on one line and used to clone or assign the |
||
| let conn = Arc::clone(&*lock!(self.0)); | ||
| #[cfg(debug_assertions)] | ||
| { | ||
| let next_read = conn.readable_request_id.load(Ordering::Acquire); | ||
|
|
@@ -427,7 +427,7 @@ impl AsyncConnection { | |
| let new_connection = | ||
| AsyncConnection::new(request.connection_params(), request.timeout_at) | ||
| .await?; | ||
| *self.0.lock().unwrap() = Arc::clone(&*new_connection.0.lock().unwrap()); | ||
| *lock!(self.0) = Arc::clone(&*lock!(new_connection.0)); | ||
| core::mem::drop(read); | ||
| // Note that this cannot recurse infinitely as we'll always be able to send at | ||
| // least one request on the new socket (though some other request may race us | ||
|
|
@@ -444,7 +444,7 @@ impl AsyncConnection { | |
| Self::timeout(request.timeout_at, conn.write.lock()).await? | ||
| }; | ||
|
|
||
| let socket_timeout = *conn.socket_new_requests_timeout.lock().unwrap(); | ||
| let socket_timeout = *lock!(conn.socket_new_requests_timeout); | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hmm, good catch I believe this mutex shouldn't be held nearly as long as it is, it should only be required for the next line then should be dropped. |
||
| let socket_timed_out = Instant::now() > socket_timeout; | ||
|
|
||
| request_id = conn.next_request_id.fetch_add(1, Ordering::Relaxed); | ||
|
|
@@ -545,7 +545,7 @@ impl AsyncConnection { | |
| match k.trim() { | ||
| "timeout" => { | ||
| let timeout_secs = (v as u64).saturating_sub(1); | ||
| *conn.socket_new_requests_timeout.lock().unwrap() = | ||
| *lock!(conn.socket_new_requests_timeout) = | ||
| Instant::now() | ||
| .checked_add(Duration::from_secs(timeout_secs)) | ||
| .unwrap_or(Instant::now()); | ||
|
|
||
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.
I do not believe any of the calls within either lock here can panic at all.