Skip to content

Occasional 401 Response when token expires #218

Closed
@mchieco

Description

@mchieco

I am currently running this on a long standing server that caches the client instance for the lifetime of the application.

Every once and a while, there is a flaky 401 that comes back from the client, subsequent runs work perfectly fine.

After reading through the client code, it looks like it may be a race condition with the expiry of the github token cache and then making the api call?

https://github.com/yanyongyu/githubkit/blob/master/githubkit/auth/app.py#L208 will check to see if the key is in the cache, so if its expired, it will fetch a new one perfectly fine. But what happens if the cache is there, but then the token expires within milliseconds of it attaching it to the api call. I believe that's what is leading to the 401 in these cases.

If you do believe that is the issue, I can certainly open up a PR to add some sort of buffer to the cache expiry to refresh the token x seconds (whatever we think is best) before it actually expires.

Happy to provide any other details/findings.

The exception is

RequestFailed
Response(401 Unauthorized, data_model=typing.Any)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions