Skip to content

Commit b453f1f

Browse files
authored
fix: tolerate re-import on an already-authorized pool session key (#104)
Session files persisted by earlier runs (where the import succeeded but the login was never finalized client-side) hold a key that already carries the account authorization; re-importing onto it is rejected by the server with AUTH_BYTES_INVALID and the bootstrap aborted. Treat AUTH_BYTES_INVALID on import as already-authorized: finalize the login client-side with the user id returned by exportAuthorization and let the workers verify the session by use, falling back to the sequential download if it turns out to be broken.
2 parents c78ba87 + 1f87e13 commit b453f1f

1 file changed

Lines changed: 15 additions & 2 deletions

File tree

TelegramDownloader/Data/TelegramService.cs

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -350,8 +350,21 @@ private static bool ShouldUseMultiConnection(TL.Document document)
350350
// With the UserId recorded, WTelegram's GetClientForDC
351351
// handles the per-file-DC authorization automatically.
352352
Auth_ExportedAuthorization exported = await client.Auth_ExportAuthorization(dc.id);
353-
Auth_AuthorizationBase auth = await pc.Auth_ImportAuthorization(exported.id, exported.bytes);
354-
pc.LoginAlreadyDone(auth);
353+
Auth_AuthorizationBase auth = null;
354+
try
355+
{
356+
auth = await pc.Auth_ImportAuthorization(exported.id, exported.bytes);
357+
}
358+
catch (RpcException rex) when (rex.Message == "AUTH_BYTES_INVALID")
359+
{
360+
// Session persisted by an earlier run whose import
361+
// succeeded but whose login was never finalized: the
362+
// key already holds the account authorization and
363+
// re-importing onto it is rejected. Record the login
364+
// client-side and let the workers verify by use.
365+
_logger.LogInformation("Download pool client {Index}: key already authorized on a previous run", index);
366+
}
367+
pc.LoginAlreadyDone(auth ?? new Auth_Authorization { user = new User { id = exported.id } });
355368
}
356369
_logger.LogInformation("Download pool client {Index} ready (homed on DC {Dc})", index, dc.id);
357370
return pc;

0 commit comments

Comments
 (0)