Skip to content

Commit fd88c43

Browse files
jkczyzclaude
andcommitted
Fix task-slot collision when pathfinding scores sync is enabled
The pathfinding scores sync task claimed the runtime's single background-processor slot, which LDK's background processor also claims later during startup. With a scores sync URL configured, node startup tripped a debug_assert in debug builds; in release builds the second spawn silently dropped the scores-sync task's join handle, so the task was detached and never joined at shutdown. Spawn it as a cancellable background task instead, matching the RGS gossip sync task, so it is cancelled with the other such tasks in Node::stop. Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
1 parent 150f370 commit fd88c43

2 files changed

Lines changed: 21 additions & 1 deletion

File tree

src/scoring.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ pub fn setup_background_pathfinding_scores_sync(
2626

2727
let logger = Arc::clone(&logger);
2828

29-
runtime.spawn_background_processor_task(async move {
29+
runtime.spawn_cancellable_background_task(async move {
3030
let mut interval = tokio::time::interval(EXTERNAL_PATHFINDING_SCORES_SYNC_INTERVAL);
3131
loop {
3232
tokio::select! {

tests/integration_tests_rust.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,26 @@ async fn start_stop_reinit() {
551551
reinitialized_node.stop().unwrap();
552552
}
553553

554+
// The scores-sync task runs alongside LDK's background processor, which claims the runtime's
555+
// single background-processor slot; startup must not panic with both configured.
556+
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
557+
async fn start_stop_with_pathfinding_scores_sync() {
558+
let (_bitcoind, electrsd) = setup_bitcoind_and_electrsd();
559+
let config = random_config(true);
560+
561+
let esplora_url = format!("http://{}", electrsd.esplora_url.as_ref().unwrap());
562+
563+
let mut sync_config = EsploraSyncConfig::default();
564+
sync_config.background_sync_config = None;
565+
setup_builder!(builder, config.node_config);
566+
builder.set_chain_source_esplora(esplora_url.clone(), Some(sync_config));
567+
builder.set_pathfinding_scores_source(esplora_url);
568+
569+
let node = builder.build(config.node_entropy.into()).unwrap();
570+
node.start().unwrap();
571+
node.stop().unwrap();
572+
}
573+
554574
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
555575
async fn onchain_send_receive() {
556576
let (bitcoind, electrsd) = setup_bitcoind_and_electrsd();

0 commit comments

Comments
 (0)