Skip to content

tg daemon stop waits out a FLOOD_WAIT in the dialog pass or a sync job, past its 10 s timeout #64

Closed

Description

@neoromantic

Found while fixing #56. A stop now ends the daemon's dialog pass at the next dialog and waits for at most one running sync job, but neither can be cut short while a request is waiting out a FLOOD_WAIT.

The daemon's clients wait out FLOOD_WAITs of up to five minutes inside the request (floodWaiter.maxWait in createDaemonClient). When SIGTERM arrives during such a wait:

  • in the startup or reconnect dialog pass, iterDialogs stays inside its messages.getDialogs call until the wait ends, so the pass only sees the stop flag afterwards;
  • in a sync job, the main loop awaits the job's messages.getHistory, so it only checks the flag after the wait.

tg daemon stop gives up after its 10 s timeout ("Daemon did not stop within 10 seconds. Use --force to forcefully kill."), while the daemon keeps running until the wait ends and then stops cleanly. --force kills it, which loses session writes made since the last save.

The daemon passes no per-call abortSignal to these requests, so today the only way to cut the wait short is to tear the client down, which rejects every request in flight and would need its own handling of interrupted jobs.

Possible fix: give the dialog pass and the sync jobs an AbortSignal that the stop aborts, so a request waiting out a FLOOD_WAIT ends at once, the job keeps its row as it was (pending, not failed) and the pass is treated as stopped.

Done when tg daemon stop during a FLOOD_WAIT in the dialog pass or in a sync job stops the daemon within its timeout, the job stays pending for the next start, and no error is logged for the cut-short request.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions