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

fix(abci): invalid error returned when codec terminates #117

Merged
merged 3 commits into from
Nov 28, 2024
Merged
Show file tree
Hide file tree
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
19 changes: 16 additions & 3 deletions abci/src/server/codec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,18 @@ impl<'a> Codec {

Self::process_worker_queues(codec, request_tx, response_rx, cancel).await;
}

/// Worker that moves messages between codec and requests and responses
/// queues.
///
/// Reads messages from ABCI Client from `codec`, sends them to Tenderdash
/// via `request_tx`, receives Tenderdash responses from `response_rx`
/// and forwards to
///
/// ## Error handling
///
/// On error, it cancels the `cancel` [CancellationToken] and exits.
/// It causes `response_rx` to be closed.
async fn process_worker_queues<L: AsyncRead + AsyncWrite + Unpin>(
mut codec: Framed<L, Coder>,
request_tx: Sender<proto::abci::Request>,
Expand Down Expand Up @@ -149,9 +161,10 @@ impl<'a> Codec {
}

pub fn send(&self, value: Response) -> Result<(), Error> {
self.response_tx
.blocking_send(value)
.map_err(|e| Error::Async(e.to_string()))
self.response_tx.blocking_send(value).map_err(|_| {
// channel closed, `process_worker_queues` either errored or cancelled
Error::Cancelled()
})
}
}

Expand Down
8 changes: 6 additions & 2 deletions abci/tests/kvstore.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,17 +63,21 @@ fn test_kvstore() {
fs::set_permissions(SOCKET, perms).expect("set perms");

let socket_uri = bind_address.to_string();
let _td = common::docker::TenderdashDocker::new("tenderdash", None, &socket_uri);
let td = common::docker::TenderdashDocker::new("tenderdash", None, &socket_uri);

let next_client = server.next_client();
tracing::debug!(?next_client, "next client");
assert!(matches!(
server.next_client(),
next_client,
Err(tenderdash_abci::Error::Cancelled())
));
drop(server);

let kvstore_app = kvstore.into_inner().expect("kvstore lock is poisoned");
assert_eq!(kvstore_app.persisted_state, state_reference);
assert_eq!(kvstore_app.last_block_height, 1);

drop(td);
}

/// An example storage.
Expand Down