Skip to content

Commit 7387e87

Browse files
authored
disconnect all peers to close TPC connections (#32)
1 parent 2ed4521 commit 7387e87

3 files changed

Lines changed: 16 additions & 1 deletion

File tree

Cargo.toml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ bitcoin-payment-instructions = { version = "0.5.0", default-features = false, fe
1212
"http",
1313
] }
1414
# Branch: https://github.com/moneydevkit/ldk-node/commits/lsp-0.7.0_accept-underpaying-htlcs_with_timing_logs
15-
ldk-node = { default-features = false, git = "https://github.com/moneydevkit/ldk-node.git", rev = "11790803d7da219cb8dd0a03e6ea021ef122d2c4" }
15+
ldk-node = { default-features = false, git = "https://github.com/moneydevkit/ldk-node.git", rev = "4309f479106aff3d768524a157e2a4178d48eaa5" }
16+
#ldk-node = { path = "../ldk-node" }
17+
1618
napi = { version = "2", features = ["napi4"] }
1719
napi-derive = "2"
1820
tokio = { version = "1", features = ["rt-multi-thread"] }

index.d.ts

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,12 @@ export declare class MdkNode {
7575
* Destroy the node, dropping the inner Rust Node and its tokio runtime immediately.
7676
* This prevents zombie processes on serverless platforms where GC is non-deterministic.
7777
* After calling destroy(), any further method calls on this node will panic.
78+
*
79+
* Always disconnects all peers first to close TCP connections. This is critical on
80+
* serverless platforms (e.g., Vercel) where the execution context may freeze after the
81+
* handler returns — a lingering TCP connection tricks the LSP into thinking the peer
82+
* is still reachable, causing it to forward HTLCs directly instead of intercepting
83+
* them and sending a webhook.
7884
*/
7985
destroy(): void
8086
getNodeId(): string

src/lib.rs

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -392,9 +392,16 @@ impl MdkNode {
392392
/// Destroy the node, dropping the inner Rust Node and its tokio runtime immediately.
393393
/// This prevents zombie processes on serverless platforms where GC is non-deterministic.
394394
/// After calling destroy(), any further method calls on this node will panic.
395+
///
396+
/// Always disconnects all peers first to close TCP connections. This is critical on
397+
/// serverless platforms (e.g., Vercel) where the execution context may freeze after the
398+
/// handler returns — a lingering TCP connection tricks the LSP into thinking the peer
399+
/// is still reachable, causing it to forward HTLCs directly instead of intercepting
400+
/// them and sending a webhook.
395401
#[napi]
396402
pub fn destroy(&mut self) -> napi::Result<()> {
397403
if let Some(node) = self.node.take() {
404+
node.disconnect_all_peers();
398405
let _ = node.stop();
399406
drop(node);
400407
}

0 commit comments

Comments
 (0)