aboutsummaryrefslogtreecommitdiffstats
path: root/patches/README.md
blob: b3bf13227372ec708591d98a58c19d97153f0a84 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# patches

## `@asoltys+clightning-client+0.1.10.patch`

Fixes the reconnect logic in `@asoltys/clightning-client` (v0.1.10) so a dropped
cl RPC connection actually recovers.

**Bug:** `reconnect()` called `this.client.connect()` on the *same* socket that
had already emitted `error`/`close`. A destroyed socket can't be reconnected, so
after a `cl` restart the client wedged, looping `connect ENOENT …/lightning-rpc`
forever — spamming logs and leaking a socket+timer each time — and never
recovered. (If `connect()` threw, `reconnectTimeout` was also left set, which
permanently blocked every future `reconnect()`.)

**Fix:** factor the socket+readline+handlers setup into `_setup()` which builds a
**fresh** socket each (re)connection and renews `clientConnectionPromise` (so
`call()` blocks until the reconnect is live). `reconnect()` now clears its guard
*before* reconnecting and retries on failure.

This is defense-in-depth: the app already neutralises the broken loop in
`lib/ln.ts` (`dropClient()` tears the dead client down and the proxy makes a fresh
`LightningClient`). This patch fixes the library itself for any path that relies
on its own reconnect.

### How to wire it in (bun)

`bun patch` couldn't run in this checkout (node_modules link EEXIST), so this
patch was generated by hand and verified to apply cleanly (`git apply --check`).
To register it so `bun install` re-applies it, in a clean checkout:

```sh
bun patch @asoltys/clightning-client
# copy patches/clightning-client-index.fixed.js over the printed editable
#   node_modules/@asoltys/clightning-client/index.js
bun patch --commit node_modules/@asoltys/clightning-client
```

That writes bun's own `patches/…` file and the `patchedDependencies` entry in
`package.json`. Alternatively, apply this patch directly in the image build:
`git apply patches/@asoltys+clightning-client+0.1.10.patch` against the installed
package. `clightning-client-index.fixed.js` is the full patched file for reference.