aboutsummaryrefslogtreecommitdiffstats
path: root/lib/notes.ts
diff options
context:
space:
mode:
authorAdam Soltys <adam@coinos.io>2026-06-04 18:17:47 -0700
committerAdam Soltys <adam@coinos.io>2026-06-04 18:17:47 -0700
commitbd1ece38e42751575ac2e03a5c795b5b109653ac (patch)
treece5f648953b89db5ce94f6f8218ed35799a4f960 /lib/notes.ts
parentbe896868de55ef82b268d8c9f92c3f0ba857fed8 (diff)
downloadcoinos-server-bd1ece38e42751575ac2e03a5c795b5b109653ac.tar.gz
coinos-server-bd1ece38e42751575ac2e03a5c795b5b109653ac.zip
ln/lightning: watchdog recycles zombie receive-listener socket
On 2026-06-04 cl restarted (autoheal, after its 15s healthcheck timed out), and the app's waitanyinvoice long-poll hung on the now-dead listen socket. listenerActive stayed true forever, so ensureListenerAlive never restarted it, and incoming lightning payments stopped crediting for ~2h until a manual app restart. The per-call RPC timeout in ln.ts can't catch this: waitanyinvoice is intentionally in NO_TIMEOUT (it's meant to block). Fix: ensureListenerAlive (runs every 120s) now also detects a stalled listener — active but blocked in waitanyinvoice for >5min. It probes cl via the main ln socket (getinfo); only if cl is actually alive does it treat the listen socket as a zombie, call lnListen.reset() (new: drops the proxy's socket so the next call reconnects), and re-arm. A listenerEpoch guard makes the wedged invocation bow out when its waitanyinvoice finally rejects, so we never run two listeners concurrently and never double-credit. Verified with a state-machine test covering normal receive, quiet-but-healthy (left alone), stall+cl-alive (recycled), stall+cl-down (left alone), and the no-double-listener race. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Diffstat (limited to 'lib/notes.ts')
0 files changed, 0 insertions, 0 deletions
{ color: #B06; font-weight: bold } /* Name.Tag */ .highlight .nv { color: #369 } /* Name.Variable */ .highlight .ow { color: #080 } /* Operator.Word */ .highlight .w { color: #BBB } /* Text.Whitespace */ .highlight .mb { color: #00D; font-weight: bold } /* Literal.Number.Bin */ .highlight .mf { color: #00D; font-weight: bold } /* Literal.Number.Float */ .highlight .mh { color: #00D; font-weight: bold } /* Literal.Number.Hex */ .highlight .mi { color: #00D; font-weight: bold } /* Literal.Number.Integer */ .highlight .mo { color: #00D; font-weight: bold } /* Literal.Number.Oct */ .highlight .sa { color: #D20; background-color: #FFF0F0 } /* Literal.String.Affix */ .highlight .sb { color: #D20; background-color: #FFF0F0 } /* Literal.String.Backtick */ .highlight .sc { color: #D20; background-color: #FFF0F0 } /* Literal.String.Char */ .highlight .dl { color: #D20; background-color: #FFF0F0 } /* Literal.String.Delimiter */ .highlight .sd { color: #D20; background-color: #FFF0F0 } /* Literal.String.Doc */ .highlight .s2 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Double */ .highlight .se { color: #04D; background-color: #FFF0F0 } /* Literal.String.Escape */ .highlight .sh { color: #D20; background-color: #FFF0F0 } /* Literal.String.Heredoc */ .highlight .si { color: #33B; background-color: #FFF0F0 } /* Literal.String.Interpol */ .highlight .sx { color: #2B2; background-color: #F0FFF0 } /* Literal.String.Other */ .highlight .sr { color: #080; background-color: #FFF0FF } /* Literal.String.Regex */ .highlight .s1 { color: #D20; background-color: #FFF0F0 } /* Literal.String.Single */ .highlight .ss { color: #A60; background-color: #FFF0F0 } /* Literal.String.Symbol */ .highlight .bp { color: #038 } /* Name.Builtin.Pseudo */ .highlight .fm { color: #06B; font-weight: bold } /* Name.Function.Magic */ .highlight .vc { color: #369 } /* Name.Variable.Class */ .highlight .vg { color: #D70 } /* Name.Variable.Global */ .highlight .vi { color: #33B } /* Name.Variable.Instance */ .highlight .vm { color: #369 } /* Name.Variable.Magic */ .highlight .il { color: #00D; font-weight: bold } /* Literal.Number.Integer.Long */
import { auth, fd, post } from "$lib/utils";
import { fail } from "@sveltejs/kit";

type Error = {
	message: string;
};

export default async ({ cookies, request }) => {
	const form = await fd(request);

	if (form.tab === "account") {
		form.notify = form.notify === "on";
		form.push = form.push === "on";
		form.nip5 = form.nip5 === "on";
		form.prompt = form.prompt === "on";
		form.autowithdraw = form.autowithdraw === "on";
	}

	try {
		const { user } = await post("/user", form, auth(cookies));

		if (user.language) cookies.set("lang", user.language, { path: "/" });

		return { user, success: true };
	} catch (e) {
		const { message } = e as Error;
		return fail(400, { message });
	}
};