Skip to content

Commit e729580

Browse files
committed
Add test that drops the node in an async context
.. as tokio tends to panic if dropping a runtime in an async context and we're not super careful. Here, we add some test coverage for this edge case in Rust tests.
1 parent f12f9e7 commit e729580

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/lib.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -680,10 +680,10 @@ impl Node {
680680
log_debug!(self.logger, "Stopped chain sources.");
681681

682682
// Wait until all background tasks (mod LDK's background processor) are done.
683-
let runtime_handle = runtime.handle();
683+
let runtime_2 = Arc::clone(&runtime);
684684
if let Some(mut tasks) = self.background_tasks.lock().unwrap().take() {
685685
tokio::task::block_in_place(move || {
686-
runtime_handle.block_on(async {
686+
runtime_2.block_on(async {
687687
loop {
688688
let timeout_fut = tokio::time::timeout(
689689
Duration::from_secs(BACKGROUND_TASK_SHUTDOWN_TIMEOUT_SECS),
@@ -721,10 +721,9 @@ impl Node {
721721
if let Some(background_processor_task) =
722722
self.background_processor_task.lock().unwrap().take()
723723
{
724-
let runtime_handle = runtime.handle();
725724
let abort_handle = background_processor_task.abort_handle();
726725
let timeout_res = tokio::task::block_in_place(move || {
727-
runtime_handle.block_on(async {
726+
runtime.block_on(async {
728727
tokio::time::timeout(
729728
Duration::from_secs(LDK_EVENT_HANDLER_SHUTDOWN_TIMEOUT_SECS),
730729
background_processor_task,

tests/integration_tests_rust.rs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1381,3 +1381,14 @@ fn facade_logging() {
13811381
validate_log_entry(entry);
13821382
}
13831383
}
1384+
1385+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
1386+
async fn drop_in_async_context() {
1387+
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
1388+
let chain_source = TestChainSource::Esplora(&electrsd);
1389+
let seed_bytes = vec![42u8; 64];
1390+
1391+
let config = random_config(true);
1392+
let node = setup_node(&chain_source, config, Some(seed_bytes));
1393+
node.stop().unwrap();
1394+
}

0 commit comments

Comments
 (0)