Skip to content

fix(client): race in connection errors propagation #184

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 31 additions & 6 deletions src/client/legacy/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -582,16 +582,41 @@ where
trace!(
"http1 handshake complete, spawning background dispatcher task"
);
let (err_tx, err_rx) = tokio::sync::oneshot::channel();
executor.execute(
conn.with_upgrades()
.map_err(|e| debug!("client connection error: {}", e))
.map_err(|e| {
debug!("client connection error: {:?}", e);
trace!("sending connection error to error channel");
let _ =err_tx.send(e);
})
.map(|_| ()),
);

// Wait for 'conn' to ready up before we
// declare this tx as usable
tx.ready().await.map_err(Error::tx)?;
PoolTx::Http1(tx)
trace!("waiting for connection to be ready");
match tx.ready().await {
Ok(_) => {
trace!("connection is ready");
drop(err_rx);
PoolTx::Http1(tx)
}
Err(e) if e.is_closed() => {
trace!("connection channel closed, checking for connection error");
match err_rx.await {
Ok(err) => {
trace!("received connection error: {:?}", err);
return Err(Error::tx(err));
}
Err(_) => {
trace!("error channel closed, returning the vague ChannelClosed error");
return Err(Error::tx(e));
}
}
}
Err(e) => {
trace!("connection readiness failed: {:?}", e);
return Err(Error::tx(e));
}
}
}
#[cfg(not(feature = "http1"))] {
panic!("http1 feature is not enabled");
Expand Down