Skip to content

Suppress expected ‘Session is reset’ warning during client shutdown #58

Description

@kfastov

Summary

After a successful QR + 2FA login, tgcli may print an alarming warning:

[WRN] [updates] [USER redacted] error fetching common difference: Error: Session is reset
    at MtprotoSession.resetState (...)
    at SessionConnection.destroy (...)
    at async NetworkManager.destroy (...)
    at async MtClient.disconnect (...)

The same warning is reproducible with tgcli doctor --connect.

Authentication remains valid and live Telegram requests succeed, so this appears to be an expected shutdown cancellation being logged as a warning rather than an actual session failure.

Environment

  • tgcli 2.2.3
  • Homebrew installation
  • Node.js 22
  • macOS

Steps to reproduce

  1. Run tgcli auth --qr --qr-file /tmp/tgcli-auth.png.
  2. Scan the QR code and enter the 2FA password.
  3. Observe Session is reset while the command shuts down.

Alternative reproduction:

tgcli doctor --connect

Current behavior

The command reports a valid connection:

AUTHENTICATED: true
CONNECTED: true

A subsequent read-only request also succeeds:

tgcli --json channels list --limit 1

However, client teardown can log error fetching common difference: Error: Session is reset, which makes a successful login look broken.

Expected behavior

Expected cancellation of an in-flight updates/difference request during intentional client shutdown should be suppressed or downgraded to debug-level output.

Real session resets outside intentional shutdown should remain visible and retain the existing recovery behavior.

Likely cause

TelegramClient.destroy() disconnects mtcute while the updates manager has a common-difference request in flight. MtprotoSession.resetState() rejects pending RPCs with MtcuteError("Session is reset"), and the updates manager logs that rejection as a warning.

Possible direction

Track intentional shutdown and suppress only this expected teardown error, or stop the updates manager cleanly before destroying the MTProto client. Avoid broadly hiding Session is reset, since tgcli already uses it for genuine recovery paths.

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions