From 4aecb1a72c13998d1fe85381c29b60e483e1c5b2 Mon Sep 17 00:00:00 2001 From: moralpriest Date: Thu, 9 Jul 2026 02:40:55 -0600 Subject: [PATCH] fix(walletapi): add configurable 10s timeout to RPC calls Add a package-level `rpcCallTimeout` variable (default 10s) used in `Client.Call` to prevent RPC calls from hanging indefinitely on half-open WebSocket connections. This is especially important on mobile where NAT timeouts silently kill connections without TCP-level detection. All JSON-RPC calls (GetEncryptedBalance, GetInfo, SendRawTransaction, etc.) complete in <1s under normal conditions; the 10s default provides 10x margin on normal networks and 5x margin on degraded connections. Wallets can override `rpcCallTimeout` to tune for their platform. --- walletapi/daemon_communication.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/walletapi/daemon_communication.go b/walletapi/daemon_communication.go index 2cffea05..b21af215 100644 --- a/walletapi/daemon_communication.go +++ b/walletapi/daemon_communication.go @@ -62,6 +62,7 @@ var Connected bool = false var daemon_height int64 var daemon_topoheight int64 var last_event_topoheight_tracked int64 +var rpcCallTimeout = 10 * time.Second // per-call timeout preventing hangs on dead connections // return daemon height func Get_Daemon_Height() int64 { @@ -219,7 +220,9 @@ func (w *Wallet_Memory) sync_loop() { } func (cli *Client) Call(method string, params interface{}, result interface{}) error { - return cli.RPC.CallResult(context.Background(), method, params, result) + ctx, cancel := context.WithTimeout(context.Background(), rpcCallTimeout) + defer cancel() + return cli.RPC.CallResult(ctx, method, params, result) } // returns whether wallet was online some time ago