Files
Juraj Bednar dbb08624d7 fix: release only expired reservation leases at startup
With reset_reserved_balance_on_startup (default true) every boot called
reset_all_reserved_balances, which marked every active ReservationRelease
released and set every ApiKey.reserved_balance to 0. A second process on
the same database (a replica, a rolling deploy, a one-off container
started against the live DB) therefore released the reservations of
requests the running process was still serving. Those requests were then
served unbilled (release is terminal, so the finalizer cannot charge),
and the reserved funds became spendable again while the request ran.

The setting is persisted in each node's settings row on first boot, so
changing its default would not reach existing nodes. Instead the startup
step now runs the lease-guarded sweep the background task already uses
(release_stale_reservations with stale_reservation_timeout_seconds):
in-flight reservations, whose leases the heartbeat renews, survive; a
reservation whose lease expired is released and only its own msats are
subtracted from its keys' reserved_balance. reset_all_reserved_balances
had no other caller and is removed.

Trade-off: after a crash, the dead process's reservations are released
once their lease expires (up to stale_reservation_timeout_seconds, 300 s by
default) instead of at boot, the same delay a client disconnect already
gets.
2026-10-23 01:28:40 +02:00
..
2025-08-09 14:55:26 -03:00
2026-05-14 15:40:49 +02:00
2026-07-01 17:01:32 +02:00
2026-10-07 07:07:57 +00:00