Skip to content

Commit

Permalink
fix: panic on broken connection
Browse files Browse the repository at this point in the history
  • Loading branch information
akostylev0 committed Mar 21, 2024
1 parent 5212de7 commit 3f93d28
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 6 deletions.
13 changes: 8 additions & 5 deletions tvm-grpc/src/transaction_emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ use std::sync::{Arc, OnceLock};
use std::time::Duration;
use futures::Stream;
use tonic::{async_trait, Request, Response, Status, Streaming};
use tracing::{error, instrument};
use tracing::instrument;
use anyhow::anyhow;
use async_stream::stream;
use tokio_stream::StreamExt;
Expand Down Expand Up @@ -55,7 +55,10 @@ impl BaseTransactionEmulatorService for TransactionEmulatorService {
SetLibs(req) => set_libs(&mut state, req).map(SetLibsResponse),
};

oneshot.send(response).expect("failed to send response");
if let Err(e) = oneshot.send(response) {
tracing::error!(error = ?e, "failed to send response");
break;
}
}
Command::Drop => { break; }
}
Expand All @@ -75,17 +78,17 @@ impl BaseTransactionEmulatorService for TransactionEmulatorService {
yield response.map(|r| TransactionEmulatorResponse { request_id, response: Some(r) })
},
Ok(Ok(TransactionEmulatorRequest { request_id, request: None })) => {
error!(error = ?anyhow!("empty request"), request_id=request_id);
tracing::error!(error = ?anyhow!("empty request"), request_id=request_id);

break
},
Ok(Err(e)) => {
error!(error = ?e);
tracing::error!(error = ?e);

break
}
Err(e) => {
error!(error = ?e);
tracing::error!(error = ?e);

break
}
Expand Down
5 changes: 4 additions & 1 deletion tvm-grpc/src/tvm_emulator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,10 @@ impl BaseTvmEmulatorService for TvmEmulatorService {
SetC7(req) => set_c7(&mut state, req).map(SetC7Response),
};

oneshot.send(response).expect("failed to send response");
if let Err(e) = oneshot.send(response) {
tracing::error!(error = ?e, "failed to send response");
break;
}
},
Command::Drop => { break; }
}
Expand Down

0 comments on commit 3f93d28

Please sign in to comment.