Skip to content

Commit

Permalink
revert
Browse files Browse the repository at this point in the history
  • Loading branch information
driftluo committed Dec 24, 2024
1 parent cd07c10 commit 5be74de
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 6 deletions.
19 changes: 13 additions & 6 deletions src/rpc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,17 +25,24 @@ pub(crate) fn block_on<F: Send>(future: impl Future<Output = F> + Send) -> F {
tokio::runtime::RuntimeFlavor::MultiThread
) =>
{
println!("1234");
tokio::task::block_in_place(|| h.block_on(timeout).unwrap())
}
// if we on the current runtime, it must use another thread to poll this future,
// can't block on current runtime, it will block current reactor to stop forever
// in tokio runtime, this time will panic
Ok(_) => std::thread::scope(|s| {
s.spawn(|| RUNTIME.with(|rt| rt.block_on(timeout).unwrap()))
.join()
.unwrap()
}),
Err(_) => RUNTIME.with(|rt| rt.block_on(timeout).unwrap()),
Ok(_) => {
println!("12345");
std::thread::scope(|s| {
s.spawn(|| RUNTIME.with(|rt| rt.block_on(timeout).unwrap()))
.join()
.unwrap()
})
}
Err(_) => {
println!("123456");
RUNTIME.with(|rt| rt.block_on(timeout).unwrap())
}
}
}

Expand Down
15 changes: 15 additions & 0 deletions src/tests/ckb_rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,21 @@ fn test_cargo_hang_4() {
println!("999");
}

#[test]
fn test_cargo_hang_5() {
use std::cell::LazyCell;
thread_local! {
pub static RUNTIME: LazyCell<tokio::runtime::Runtime> =
LazyCell::new(|| tokio::runtime::Builder::new_current_thread().enable_all().build().unwrap());
}
let ckb_client = crate::rpc::CkbRpcAsyncClient::new(TEST_CKB_RPC_URL);
let block = RUNTIME
.with(|rt| rt.block_on(ckb_client.get_block_with_cycles(BLOCK_HASH_NOT_EXIST.clone())));
let block = block.unwrap();
// assert!(block.is_none());
println!("999");
}

#[test]
fn test_get_packed_block_with_cycles_fail() {
let ckb_client = CkbRpcClient::new(TEST_CKB_RPC_URL);
Expand Down

0 comments on commit 5be74de

Please sign in to comment.