-
-
Notifications
You must be signed in to change notification settings - Fork 142
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return 401 unauthorized errors #1458
Comments
Are there any logs near the We have following method: func (c *Client) isPermanentError(err error) bool {
return errors.Is(err, exchange.ErrKeyFingerprintNotFound)
} That is used in Lines 60 to 81 in 244876a
If true, we can change |
Can you please try https://github.com/gotd/td/releases/tag/v0.114.0-alpha.0? |
The If not, you can do following: for {
select {
case <-ctx.Done():
return ctx.Err()
case <-time.After(time.Second * 10):
s, err := client.Self(ctx)
if auth.IsUnauthorized(err) {
return errors.Wrap(err, "got unauthorized")
}
fmt.Println("Current user:", s.FirstName)
}
} I've checked this on testserver. Update handling disabled:
Update handling enabled:
Same logic should apply to Please ping me here if issue is not resolved, I will reopen. |
Also you can use new |
Thanks! I will test this later. So // See https://github.com/gotd/td/issues/1458.
if errors.Is(err, exchange.ErrKeyFingerprintNotFound) {
return true
}
if tgerr.Is(err, "AUTH_KEY_UNREGISTERED") || tgerr.Is(err, "SESSION_EXPIRED") {
return true
}
if auth.IsUnauthorized(err) {
return true
}
return false |
Yes, you can check for any error, the #1478 handling can be pretty flexible. |
BTW I think that AUTH_KEY_DUPLICATED should have 401 code too and this code should handle it. if tgerr.Is(err, "AUTH_KEY_UNREGISTERED", "SESSION_EXPIRED", "AUTH_KEY_DUPLICATED") {
return true
} list, thank you. |
Description: status of the proposed feature
Currently, when using
gotd
with long running process, when a session gets disconnected, for example withAUTH_KEY_UNREGISTERED
, orSESSION_EXPIRED/REVOKED
error, theclient.Run
function does not return an error, it only logs it. This means that the client ends up looping indefinitely, logging an error:Got error on self.... AUTH_KEY_UNREGISTERED|SESSION_EXPIRED
.And this is hard to catch because if you do not use the provided logger(a *zap.Logger instance), you won't be able to understand what is happening.
As you can see here, in the
telegram/connect.go
:Here is an example code where the client tends to loop indefinitely:
Description: possible solution
The solution would be to detect those 401 errors, and return them immediately, so the user of the library can handle them properly.
Or at least, make it more explicit for people not using the standard
*zap.Logger
that something is not working right now.Or, provide an example that shows how to check for those errors. Like checking if the session is currently still working, and no
AUTH_KEY_UNREGISTERED
orSESSION_EXPIRED
errors are occuring.So, I suppose doing something similar:
Current workaround
In order to detect it, what I'm doing right now is to set a timeout with
time.After
, while running theclient.Run
function in a goroutine on a function that is expected to take less than 10 seconds.The timeout is like 30 seconds, and it allows me to detect that a session is now unregistered / expired.
References
https://core.telegram.org/api/errors#401-unauthorized
Funding
So, I set a small 20$ funding depending on the difficulty of the issue, I may slightly increase it if its hard to do.
https://polar.sh/gotd/td/issues/1458
The text was updated successfully, but these errors were encountered: