Skip to content

Commit 90f2447

Browse files
committed
Refactor sleep with tokio::time::timeout
1 parent fcb157a commit 90f2447

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

rpc/src/module/ipc.rs

+6-2
Original file line numberDiff line numberDiff line change
@@ -752,12 +752,13 @@ impl IpcRpc for IpcRpcImpl {
752752
pipesfin.close();
753753
}
754754
});
755-
let pipesfin = pipesctx.clone();
756755
// In any case, we will close all pipes after a certain period of time.
757756
// This ensures that the function always completes if the ipc script is not written as expected.
757+
let pipesfin = pipesctx.clone();
758+
let exit = tokio::sync::oneshot::channel();
758759
self.shared.async_handle().spawn({
759760
async move {
760-
tokio::time::sleep(tokio::time::Duration::from_secs(8)).await;
761+
let _ = tokio::time::timeout(tokio::time::Duration::from_secs(8), exit.1).await;
761762
pipesfin.close();
762763
}
763764
});
@@ -802,6 +803,9 @@ impl IpcRpc for IpcRpcImpl {
802803
.deref_mut(),
803804
)
804805
.map_err(|e| RPCError::custom_with_error(RPCError::IPC, e))?;
806+
exit.0
807+
.send(())
808+
.map_err(|_| RPCError::custom_with_error(RPCError::IPC, "Unexpected"))?;
805809
Ok(IpcResponse {
806810
version: Uint64::from(resp.version() as u64),
807811
error_code: Uint64::from(resp.error_code()),

0 commit comments

Comments
 (0)