Skip to content

Fix data race on injectedHTTPClient in client package#1616

Closed
Copilot wants to merge 2 commits intomasterfrom
copilot/investigate-flaky-test
Closed

Fix data race on injectedHTTPClient in client package#1616
Copilot wants to merge 2 commits intomasterfrom
copilot/investigate-flaky-test

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented Apr 2, 2026

Flaky CI failures due to a data race on the package-level injectedHTTPClient variable. TestGetHTTPClient and TestHttpClientProvidesOAuth2BearerToken both run with t.Parallel() and concurrently read/write the unprotected global, tripping the -race detector and cascading failures to all concurrent tests in the package.

  • Add sync.RWMutex to guard injectedHTTPClient access in GetHTTPClient() (read) and InjectHTTPClient() (write)
var (
	injectedHTTPClient  *http.Client
	injectedHTTPClientM sync.RWMutex
)

func GetHTTPClient(config *Config) *http.Client {
	injectedHTTPClientM.RLock()
	defer injectedHTTPClientM.RUnlock()
	if injectedHTTPClient != nil {
		return injectedHTTPClient
	}
	// ...
}

func InjectHTTPClient(httpClient *http.Client) {
	injectedHTTPClientM.Lock()
	injectedHTTPClient = httpClient
	injectedHTTPClientM.Unlock()
}

Confirmed with go test -race -count=10 — zero races across iterations.

Warning

Firewall rules blocked me from connecting to one or more addresses (expand for details)

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 1.0.0.1.in-addr.arpa
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • 192.168.152.153
    • Triggering command: REDACTED, pid is -1 (packet block)
  • 8.8.8.8.in-addr.arpa
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • data.iana.org
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • en.wikipedia.org
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • example.com
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • example.org
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • expired.badssl.com
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • idontplaytheodds.com
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • smtp.gmail.com
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • test
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • tty.sdf.org
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)
  • whois.nic.io
    • Triggering command: /tmp/go-build3186497109/b001/client.test /tmp/go-build3186497109/b001/client.test -test.paniconexit0 -test.timeout=10m0s -test.count=1 /tmp/go-build3186497109/b349/vet.cfg g_.a /tmp/go-build269go1.25.5 4/pkg/tool/linux_amd64/vet . /icmp mpile 4/pkg/tool/linux-buildtags -I chain@v0.0.1-go1-errorsas mpile 4/pkg/tool/linux_amd64/vet AFX9BbFhU /go/auth/credent-atomic mpile 4/pkg/tool/linux-buildtags (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Original prompt

Reference: https://github.com/TwiN/gatus/commit/12be9facdafa392693264c59e384ba101285c71a/checks?check_suite_id=63018577703

investigate the flaky test

Add sync.RWMutex to protect concurrent read/write access to the
package-level injectedHTTPClient variable, which was causing flaky
test failures when TestGetHTTPClient and
TestHttpClientProvidesOAuth2BearerToken ran in parallel with -race.

Agent-Logs-Url: https://github.com/TwiN/gatus/sessions/5eccf19f-b033-4bf0-9d3b-4e462e7e89c4

Co-authored-by: TwiN <15699766+TwiN@users.noreply.github.com>
Copilot AI changed the title [WIP] Investigate flaky test in the testing suite Fix data race on injectedHTTPClient in client package Apr 2, 2026
Copilot AI requested a review from TwiN April 2, 2026 21:36
Copilot finished work on behalf of TwiN April 2, 2026 21:36
@OrionOth
Copy link
Copy Markdown

OrionOth commented Apr 6, 2026

@TwiN I'd like to object strongly to merging this pull request for a variety of reasons. Furthermore, I'd like to request a reversion of commits 64116ce, f925cb4 and 7208880.
It's not too late to stay on the bright path. Please don't plagiarize and ruin this software you've worked so hard on for almost 7 years now!

@TwiN
Copy link
Copy Markdown
Owner

TwiN commented Apr 7, 2026

@OrionOth I understand your stance, alas, I don't personally think there's much that can be done to prevent the usage of LLMs from becoming the norm.

I would rather create instructions (that's what some of the commits you pointed out are for) for agents to both direct them and request agents identify themselves (model/version) properly via PRs so that I can treat the PRs as such (more carefully).

At this point, I'd be willing to bet most new PRs are generated using AI agents already.

@OrionOth
Copy link
Copy Markdown

OrionOth commented Apr 7, 2026

@TwiN There seems to be some consensus that Ghostty's AI policy is one of the best an open source project can get. I don't personally agree, but as far as limiting actual slop I think it would do a fairly good job.

@TwiN TwiN closed this Apr 19, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants