fix(mtproto): route reused auth key seen during key exchange#151
Merged
Conversation
When the server cannot resolve an incoming auth key it silently sends a -404 (CodeAuthKeyNotFound), which makes clients discard the key and reconnect. Log the key id so these can be diagnosed (e.g. media/upload session reconnect storms). Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Surface why a connection's handshake ends (e.g. client EOF mid-exchange) and any proto-error code sent, to diagnose client reconnect loops such as media/upload session churn. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Bumps gotd/td to v0.156.3, which surfaces a frame bearing a non-zero auth_key_id during server key exchange as exchange.UnexpectedEncryptedError instead of failing the exchange. The server now resolves that key and dispatches the frame as a normal encrypted RPC, replying -404 only when the key is genuinely unknown. Previously the exchange read loop replied -404 to every such frame without a lookup, making clients like Telegram Desktop discard a still-valid temporary key and re-run key exchange in a tight reconnect storm. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #151 +/- ##
==========================================
- Coverage 64.39% 64.19% -0.21%
==========================================
Files 69 69
Lines 4098 4105 +7
==========================================
- Hits 2639 2635 -4
- Misses 1059 1073 +14
+ Partials 400 397 -3 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
When a client reuses an already-established auth key on a connection the server still treats as performing key exchange, the exchange read loop replied with a bare
-404(auth_key_not_found) to that encrypted frame without looking the key up. Telegram Desktop interprets a-404on a temporary key as "key destroyed", discards it and re-runs key exchange — a tight reconnect/key-exchange storm (hundreds ofClient connected/Key exchange failed: EOFper second; client logging 185×-404 ... temporary key ... destroyed).Fix
Bumps
gotd/tdto v0.156.3 (gotd/td#1777), which surfaces such a frame asexchange.UnexpectedEncryptedError(carrying the raw frame) instead of failing the exchange.serveConnnow:-404with a log line only when the key is genuinely unknown (so the client correctly re-exchanges).The blind, unlogged
-404path (exchangeConn) is removed.Verification
Rebuilt and restarted the live service against the running Telegram Desktop client:
-404 ... destroyed.0-404sent,0key-exchange failures, stable connections, normal sync resumed — sustained across multiple client retry intervals.