Skip to content

Commit 919645e

Browse files
committed
Reset aux channel properly on reconnection
1 parent 7148c90 commit 919645e

File tree

1 file changed

+10
-3
lines changed

1 file changed

+10
-3
lines changed

crates/ark/src/lsp/main_loop.rs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -366,10 +366,17 @@ impl AuxiliaryState {
366366
// Channels for communication with the auxiliary loop
367367
let (auxiliary_event_tx, auxiliary_event_rx) = tokio_unbounded_channel::<AuxiliaryEvent>();
368368

369-
// Set global instance of this channel. This is used for logging
370-
// messages from a free function.
369+
// Set global instance of this channel. This is used for interacting
370+
// with the auxiliary loop (logging messages or spawning a task) from
371+
// free functions.
371372
unsafe {
372-
AUXILIARY_EVENT_TX.set(auxiliary_event_tx.clone()).unwrap();
373+
if let Some(val) = AUXILIARY_EVENT_TX.get_mut() {
374+
// Reset channel if already set. Happens e.g. on reconnection after a refresh.
375+
*val = auxiliary_event_tx.clone();
376+
} else {
377+
// Set channel for the first time
378+
AUXILIARY_EVENT_TX.set(auxiliary_event_tx.clone()).unwrap();
379+
}
373380
}
374381

375382
// List of pending tasks for which we manage the lifecycle (mainly relay

0 commit comments

Comments
 (0)