Skip to content

Intermittent data race in TestController/RepoControllerFeatures under -race #15

Closed

Description

@braghettos

Filing this so it isn't lost: CI caught a data race once, and a re-run of the identical commit passed. It is intermittent, not deterministic — but the Go race detector does not emit false positives, so a real race exists on this path and currently has no owner.

Evidence

run commit result
CI (run 35154427430) 336bc9e FAIL — TC06-OverrideFalse: race detected during execution of test
CI re-run 336bc9e (same) pass
Local, CI's exact flags 336bc9e (same) pass, 0 race reports, 240s
--- FAIL: TestController (177.08s)
    --- FAIL: TestController/RepoControllerFeatures (177.08s)
        --- FAIL: TestController/RepoControllerFeatures/TC06-OverrideFalse (4.67s)
            testing.go:1865: race detected during execution of test

Reproduction attempt (did not trigger it):

go test ./internal/controllers/repo/ -race -tags=unit,integration -p 1 -timeout 900s -run TestController

Why it surfaced now, and why that is probably not the cause

It appeared on #14's second CI run. That commit changes only go.mod/go.sum (provider-runtime v1.3.0 → v1.3.1); the same PR passed test on the preceding commit. A dependency bump that alters scheduling is a classic way to expose a pre-existing latent race rather than introduce one — but that is a hypothesis, not a finding, and it should not be assumed.

Why it is worth chasing despite being flaky

  • A race detector hit means a genuine unsynchronised access exists; flakiness only reflects how often the scheduler interleaves the two goroutines.
  • It will keep randomly reddening unrelated PRs, which trains people to re-run CI until green — the habit that lets a real failure through.

What would actually settle it

The failing run's race stack (the WARNING: DATA RACE block with both conflicting accesses). The captured log was truncated before it — worth checking the raw job artifact, or running the suite in a loop under -race with -count=N on a machine with more cores than a local dev box.

Likely places to look, in rough order: the integration harness's shared Gitea/server fixtures across RepoControllerFeatures subtests, then anything the controller mutates concurrently with the test goroutine's assertions.

Noticed while migrating this repo to the krateo-platformops fork (#14); that PR was merged after the re-run went green, deliberately rather than silently.

🤖 Generated with Claude Code

Activity

  1. braghettos commented on Sep 18, 2026

    @braghettos
    Author

    Fourth data point, and the first one run with CI's exact command locally.

    go test -race -tags=unit,integration -p 1 -timeout 25m ./...
    
    ok  internal/controllers/localresource   194.970s
    ok  internal/controllers/repo            209.837s
    ok  (7 other packages)
    

    Running tally on the suspected race:

    run where result
    1 CI, 336bc9e FAIL — TC06-OverrideFalse: race detected
    2 CI re-run, same commit pass
    3 local, correct tags + -race pass
    4 local, full CI command incl. integration pass

    So: 1 in 4, and not reproducible on demand. That does not make it unreal — the Go race detector has no false positives, so a genuine unsynchronised access exists. It only tells us the interleaving is rare on the hardware we have.

    What this rules out is a cheap fix: there is no repro to iterate against, so any change would be speculative and unverifiable. What would actually move it:

    • The original run's WARNING: DATA RACE block. The captured log was truncated before it. If the raw job artifact for run 35154427430 is still retrievable, that single stack names both conflicting accesses and likely ends the investigation in minutes.
    • Failing that, -count=N under load on a machine with more cores than a dev box — the interleaving is scheduler-dependent, and more parallelism is the lever.

    Leaving open and unassigned rather than closing it as flaky. A race that reddens ~1 PR in 4 trains people to re-run CI until green, which is the habit that lets a real failure through — so it is worth someone's time even though nothing is visibly broken.

  2. braghettos commented on Sep 18, 2026

    @braghettos
    Author

    Resolved — and it turns out this was already fixed by #13 before the tally above was even finished.

    The stack, finally

    My previous comment said the original WARNING: DATA RACE block would end this in minutes if it were still retrievable. It was, and it did.

    It was retrievable the whole time; I was looking at the wrong thing. Run 35154427430 has run_attempt: 2, and gh run view --log serves the latest attempt — the green re-run. The failing log is attempt 1, reachable only through the API:

    gh api repos/krateo-platformops/git-provider/actions/runs/35154427430/attempts/1/jobs
    gh api repos/krateo-platformops/git-provider/actions/jobs/104990354807/logs
    

    (That log is served as binary, so plain grep silently matches nothing and reports a clean file. It needs grep -a. Worth knowing — it reads exactly like "no race here.")

    What raced

    WARNING: DATA RACE
    Write at 0x00c00047c8a0 by goroutine 187:
      go-git/plumbing/transport/client.InstallProtocol()
          .../go-git/v5@v5.19.2/plumbing/transport/client/client.go:31
      git.(*Repo).setDefaultHTTPSClient()
          internal/clients/git/git.go:121
      git.GetLatestCommitRemote.deferwrap2()
          internal/clients/git/git.go:197
      runtime.deferreturn()
      ...
      go-git.(*Remote).List()
      git.GetLatestCommitRemote()
          internal/clients/git/git.go:211
    

    Two blocks, same signature, and exactly the failing subtest — TC06-OverrideFalse.

    GetLatestCommitRemote's deferred restore called InstallProtocol to put the default client back, writing go-git's process-global transport/client.Protocols map while another goroutine was inside a remote operation reading it.

    Why it's fixed

    b8be3fe — "fix(git): stop mutating go-git's process-global transport registry" (#13) — put a sync.RWMutex around that registry: operations needing no custom client take the read lock and share go-git's default, and only the cookie-jar and capability paths write, under the exclusive lock, restoring the defaults before releasing. setDefaultHTTPSClient is gone; the surviving InstallProtocol calls are both inside the write lock.

    Timeline lines up exactly:

    when
    race, commit 336bc9e 2026-09-16 21:48Z
    this issue filed 2026-09-16 22:14Z
    fix b8be3fe merged 2026-09-17 11:39Z

    So data points 1–3 in the tally were all pre-fix, and only #4 was on fixed code. "1 in 4" was really "it failed while it was broken."

    Pinned by TestTransportRegistryIsRaceFree in internal/clients/git/transport_test.go, which reintroduces the failure mode if anyone adds an unsynchronised InstallProtocol call back.

    Worth recording

    The hypothesis in the issue body was that the provider-runtime v1.3.0 → v1.3.1 bump exposed a pre-existing latent race rather than introducing one. That was right — the racing code predated the bump; different scheduling just made the interleaving reachable.

    And the consequence was worse than a red CI run: a "concurrent map read and map write" is fatal and unrecoverable, so if it landed between provider-runtime writing krateo.io/external-create-pending and writing the create result, the managed resource wedged permanently on "cannot determine creation result". That is the same wedge tracked in core-provider#110.

    Closing as fixed by #13.

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

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