Skip to content
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

Improve Cassandra new connection errors #847

Merged
merged 2 commits into from
Oct 11, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
11 changes: 9 additions & 2 deletions shotover-proxy/src/transforms/cassandra/connection.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,9 +41,16 @@ impl CassandraConnection {
pushed_messages_tx: Option<mpsc::UnboundedSender<Messages>>,
) -> Result<Self> {
let tcp_stream = timeout(Duration::from_secs(3), TcpStream::connect(&host))
.await?
.await
.map_err(|_| {
anyhow!(
"Cassandra node at {:?} did not respond to connection attempt within 3 seconds",
host
)
})?
.map_err(|e| {
anyhow::Error::new(e).context(format!("Failed to connect to upstream: {:?}", host))
anyhow::Error::new(e)
.context(format!("Failed to connect to cassandra node: {:?}", host))
})?;

let (out_tx, out_rx) = mpsc::unbounded_channel::<Request>();
Expand Down
26 changes: 21 additions & 5 deletions shotover-proxy/src/transforms/cassandra/sink_cluster/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,18 +101,34 @@ impl ConnectionFactory {
self.tls.clone(),
self.pushed_messages_tx.clone(),
)
.await?;
.await
.map_err(|e| e.context("Failed to create new connection"))?;

for handshake_message in &self.init_handshake {
let (return_chan_tx, return_chan_rx) = oneshot::channel();
outbound.send(handshake_message.clone(), return_chan_tx)?;
return_chan_rx.await?;
outbound
.send(handshake_message.clone(), return_chan_tx)
.map_err(|e| {
anyhow!(e)
.context("Failed to initialize new connection with handshake, tx failed")
})?;
return_chan_rx.await.map_err(|e| {
anyhow!(e).context("Failed to initialize new connection with handshake, rx failed")
})?;
}

if let Some(use_message) = &self.use_message {
let (return_chan_tx, return_chan_rx) = oneshot::channel();
outbound.send(use_message.clone(), return_chan_tx)?;
return_chan_rx.await?;
outbound
.send(use_message.clone(), return_chan_tx)
.map_err(|e| {
anyhow!(e)
.context("Failed to initialize new connection with use message, tx failed")
})?;
return_chan_rx.await.map_err(|e| {
anyhow!(e)
.context("Failed to initialize new connection with use message, rx failed")
})?;
}

Ok(outbound)
Expand Down