Skip to content

[BUG]: Transport ordering makes the response cache a no-op when legacy_client = false #3612

Closed

Description

@garnertb

Expected Behavior

With legacy_client = false, the provider builds a REST client that includes a conditional-request cache (ghct.NewTransport, github.com/bored-engineer/github-conditional-http-transport). Cache: true is set unconditionally for this client.

Repeated GETs of an unchanged resource should revalidate via If-None-Match and receive 304 Not Modified, which GitHub does not charge against the primary rate limit.

Actual Behavior

The cache never produces a hit. Every request is a full 200.

newTransport composes the chain so the cache is outermost and oauth2.Transport is innermost (internal/ghclient/transport.go):

cloneTransport -> oauth2 -> logging -> retryablehttp -> throttler -> ratelimit -> ghct
                  ^ innermost                                                     ^ outermost

oauth2 is applied first so it ends up deepest; ghct is applied last so it ends up on top. RoundTripper chains execute outermost-first, so ghct sees every request before the Authorization header exists.

GitHub derives ETags from Authorization and advertises Vary: Accept, Authorization. ghct handles this — its VaryHeaders are exactly Accept, Authorization, Cookie. With the credential invisible, three paths fail:

# Path Source What goes wrong
1 store transport.go:165-174 req.Header.Values("Authorization") is empty, so the X-Varied-Authorization marker is never written
2 vary/reuse vary.go:21-25 compares HashToken("") against a missing stored value — always false
3 recompute conditional.go:45-50 recomputes the ETag without Authorization while GitHub hashed with it

Two things this is not. Authentication still works — oauth2 authenticates below the cache, so requests reach GitHub fully credentialed; "the cache broke auth" is the wrong reading. And credential rotation is not implicated: addConditionalHeaders has a third branch that recomputes from the cached body, which works correctly once Authorization is visible.

Impact is wasted rate limit and latency only — no correctness or state issue. Users on the default legacy_client = true are unaffected, which likely explains why this went unnoticed. The cache is REST-only; getGraphQLClientOptions never sets Cache.

Fix: apply oauth2.Transport so it wraps ghct rather than sitting beneath it.

Distinct from #3519, which concerns the legacy etag path caching too aggressively into stale state; this is the new client not caching at all.

Terraform Version

Terraform v1.15.8
on linux_amd64
+ provider registry.terraform.io/integrations/github v6.13.0

GitHub Installation Type

  • GitHub Enterprise Cloud with Personal Accounts (github.com)

Affected Resource(s)

Not resource-specific — every REST-backed resource and data source when legacy_client = false. The defect is in the shared client transport.

Terraform Configuration Files

provider "github" {
  owner         = "your-org"
  legacy_client = false # required to reach the affected client
}

Steps to Reproduce

A standalone repro is at TEMPORARY-repro/cache-ordering. It builds both orderings directly from the pinned libraries without importing internal/ghclient, so the core comparison can be audited without trusting this fork.

git clone -b garnertb/cache-ordering-repro https://github.com/garnertb/terraform-provider-github
cd terraform-provider-github
GOTOOLCHAIN=auto go run ./TEMPORARY-repro/cache-ordering

# optional, against the real API
GITHUB_TOKEN=$(gh auth token) GOTOOLCHAIN=auto go run ./TEMPORARY-repro/cache-ordering -live

Hermetic mode, against an httptest origin that computes ETags with GitHub's rule and returns 401 when unauthenticated:

ORDERING    ORIGIN STATUSES     CLIENT STATUSES   X-Cache:HIT   STORED X-Varied-Authorization
upstream    200 x4              200 x4            0             (marker absent)
patched     200 x1, 304 x3      200 x4            3             present, len=44
provider    200 x4              200 x4            0             (marker absent)

Live mode against api.github.com: upstream=0, patched=3 of 4.

Note that statuses must be counted at the origin. ghct rewrites a wire 304 into a 200 before returning, so client-side codes are 200 in every row; the client-side signal is X-Cache/Cache-Status.

Code of Conduct

  • I agree to follow this project's Code of Conduct

Activity

  1. github-actions commented on Aug 18, 2026

    @github-actions

    👋 Hi, and thank you for opening this issue!

    This repo is maintained by GitHub and community members on a best-effort basis. We'll get to this as soon as we can.

    You can help us prioritize by adding details, reproduction steps, or a 👍 to issues that matter to you, and by joining the discussion on open issues and PRs.


    🤖 This is an automated message.

  2. added
    Type: Bug
    on Sep 7, 2026
  3. self-assigned this
    on Sep 7, 2026
  4. added this to the v6.14.0 milestone on Sep 7, 2026
  5. stevehipwell commented on Sep 7, 2026

    @stevehipwell
    Collaborator

    Thanks for the detailed bug report @garnertb, the new client code is based on another codebase and something has been lost in translation. I've fixed the defect and added a regression test in #3635.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type: Bug

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions