-
Notifications
You must be signed in to change notification settings - Fork 106
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
Refactor connection.rs
to make fail_with
errors impossible
#1721
Changes from all commits
6e17040
57e5f2f
b12d1f1
c1e8cdd
4c75fa2
3433ccd
95b31fe
9c9d4ea
599374b
bb872bc
03d444c
f34aa89
5a64d98
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 |
---|---|---|
|
@@ -6,22 +6,21 @@ use std::{ | |
|
||
use futures::{ | ||
channel::{mpsc, oneshot}, | ||
future, ready, | ||
ready, | ||
stream::{Stream, StreamExt}, | ||
}; | ||
use tower::Service; | ||
|
||
use crate::protocol::internal::{Request, Response}; | ||
|
||
use super::{ErrorSlot, PeerError, SharedPeerError}; | ||
use super::{PeerError, SharedPeerError}; | ||
|
||
/// The "client" duplex half of a peer connection. | ||
pub struct Client { | ||
// Used to shut down the corresponding heartbeat. | ||
// This is always Some except when we take it on drop. | ||
pub(super) shutdown_tx: Option<oneshot::Sender<()>>, | ||
pub(super) server_tx: mpsc::Sender<ClientRequest>, | ||
pub(super) error_slot: ErrorSlot, | ||
} | ||
|
||
/// A message from the `peer::Client` to the `peer::Server`. | ||
|
@@ -47,8 +46,6 @@ pub(super) struct ClientRequestReceiver { | |
|
||
/// A message from the `peer::Client` to the `peer::Server`, | ||
/// after it has been received by the `peer::Server`. | ||
/// | ||
/// | ||
#[derive(Debug)] | ||
#[must_use = "tx.send() must be called before drop"] | ||
pub(super) struct InProgressClientRequest { | ||
|
@@ -98,13 +95,6 @@ impl From<ClientRequest> for InProgressClientRequest { | |
} | ||
} | ||
|
||
impl ClientRequestReceiver { | ||
/// Forwards to `inner.close()` | ||
pub fn close(&mut self) { | ||
self.inner.close() | ||
} | ||
} | ||
|
||
impl Stream for ClientRequestReceiver { | ||
type Item = InProgressClientRequest; | ||
|
||
|
@@ -199,10 +189,7 @@ impl Service<Request> for Client { | |
|
||
fn poll_ready(&mut self, cx: &mut Context<'_>) -> Poll<Result<(), Self::Error>> { | ||
if ready!(self.server_tx.poll_ready(cx)).is_err() { | ||
Poll::Ready(Err(self | ||
.error_slot | ||
.try_get_error() | ||
.expect("failed servers must set their error slot"))) | ||
Poll::Ready(Err(PeerError::ConnectionClosed.into())) | ||
} else { | ||
Poll::Ready(Ok(())) | ||
} | ||
|
@@ -221,13 +208,7 @@ impl Service<Request> for Client { | |
match self.server_tx.try_send(ClientRequest { request, span, tx }) { | ||
Err(e) => { | ||
if e.is_disconnected() { | ||
let ClientRequest { tx, .. } = e.into_inner(); | ||
let _ = tx.send(Err(PeerError::ConnectionClosed.into())); | ||
future::ready(Err(self | ||
.error_slot | ||
.try_get_error() | ||
.expect("failed servers must set their error slot"))) | ||
.boxed() | ||
Comment on lines
-224
to
-230
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. What happens to the 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. It's never sent to the There error slot here is gone by the same logic above, the error from a previous request doesn't need to be propagated back to subsequent failed attempts at new requests. |
||
async { Err(PeerError::ConnectionClosed.into()) }.boxed() | ||
} else { | ||
// sending fails when there's not enough | ||
// channel space, but we called poll_ready | ||
|
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 change replaces
error_slot
withPeerError::ConnectionClosed
.What happened to the error value that used to be here?
Are we hiding more specific errors as part of this change?
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.
possibly, but I think the errors we used to grab here were misleading and shouldn't be propagated back to this source. The error slot used to store the error that brought down a
Connection
, but that error is actually associated with one of the client requests created bycall
. We would propagate the error back to that caller over the channel and also copy it to be shared with all future callers. My instinct is that this isn't particularly useful and that we will correctly report all these errors still, they just wont end up being reported many extra times. Imo its fine for subsequent attempts to use aClient
with a deadConnection
to just say "sorry this is already closed".