Skip to content

discussion: token refresh mechanism for rest client #437

@TennyZhuang

Description

@TennyZhuang

Background: #301

The token fetched from the token server may have a TTL, see TokenResponse::expires_in. In most implementations, the value is about several hours. Our catalog client is a long-lived object, which means that we should handle the token expiration event.

There are two ways:

  1. Spawn a background task, and setup a ticker with a specified time interval, e.g. expires_in * 0.9 seconds, and refetch the token when triggered.
  • Pros: Easy to implement
  • Cons: Must trust the local timer skew
  • Cons: Must introduce a timer, which means depending on a specified async runtime
  1. Call every methods with a retry wrapper. When meeting an unauthorized error, refetch the token and retry the method.
  • Pros: Consistent with iceberg-python
  • Pros: Does not rely on local clock and specific runtime
  • Cons: When expired, thousands of concurrent requests may fail, and then all of them will trigger a token refetch, which is not ideal.
    • This can be workaround by some concurrency control, to force only one request will refetch the token and others must wait for the result, but it introduced complexity.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions