You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Daemon loses writes queued between the stop signal and its shutdown #56
Found while fixing #34. When SIGTERM or SIGINT arrives (tg daemon stop, Ctrl-C), @mtcute/bun's exit hook (utils/exit-hook.js, registered by StorageManager and the sqlite driver when a session loads) saves and closes every session file right away, then sends the signal again. That's why the daemon logs "Received SIGTERM" twice. The daemon's own graceful shutdown runs a second or more later, after the main-loop sleep and any running sync job.
In that window the clients are still connected, but their storage is closed:
the updates loop can't save pts/qts after a batch, so it errors and restarts until the process exits, and the next start fetches that difference again;
peers seen by a running sync job aren't saved to the session file;
Nothing is corrupted: the state on disk is the state at the signal. The cost is redone work and log noise on every stop of a busy daemon.
Fix: stop the updates loops and sync workers when the signal arrives, before mtcute's hook closes the storage, or close the clients from the daemon's own signal handler. Either way it means ordering our handler before mtcute's process listeners without touching mtcute internals (no supported option turns the sqlite driver's hook off in 0.32).
Done when a tg daemon stop during an active sync logs no updates-loop error and no failed save, and the live daemon smoke test still passes.
Activity
test(daemon): warn when closing a client finds its session file closed
fix(daemon): keep session files open until the daemon closes its clients
test(daemon): warn when closing a client finds its session file closed
fix(daemon): keep session files open until the daemon closes its clients
test(daemon): warn when closing a client finds its session file closed
docs: add the changelog entries for the 0.4.0 bug fixes