Bug Report: data race on VaultCredentialsServer.cacheValid
Author: Shubhamkr585Created Sep 30, 2026Updated Sep 30, 2026
LabelsType: BugComponent: Authn/z
Overview of the Issue
The cache-expiry goroutine started in VaultCredentialsServer.GetUserAndPassword sets cacheValid = false without holding vcs.mu, while GetUserAndPassword reads and writes it under that lock. go test -race reports a data race. The goroutine also looks up the global AllCredentialsServers["vault"] instead of using the receiver. I have a fix and regression test ready.
Reproduction Steps
- Check out the current main branch (commit e5e0091d44).
- Add a test that sets the Vault credentials cache TTL (vaultCacheTTL) to 1ms and repeatedly calls GetUserAndPassword on AllCredentialsServers["vault"] while the cache-expiry goroutine runs. The test is included in my PR.
- Run: go test -race -run TestVaultCredentialsServerCacheExpiryRace ./go/vt/dbconfigs/
- The race detector reports WARNING: DATA RACE on VaultCredentialsServer.cacheValid.
The cache-expiry goroutine started in VaultCredentialsServer.GetUserAndPassword (go/vt/dbconfigs/credentials.go) sets cacheValid = false without holding vcs.mu, while GetUserAndPassword reads and writes cacheValid under that lock. The goroutine also looks up the global AllCredentialsServers["vault"] instead of using the receiver.
Binary Version
Vitess main branch at commit e5e0091d44, built from source (no release binary; issue found with go test -race, go1.27.1 linux/amd64)Operating System and Environment details
WSL2 Ubuntu on Windows, Go 1.27.1 (snap)
PRETTY_NAME="Ubuntu 24.04.1 LTS"
NAME="Ubuntu"
VERSION_ID="24.04"
VERSION="24.04.1 LTS (Noble Numbat)"
VERSION_CODENAME=noble
ID=ubuntu
ID_LIKE=debian
HOME_URL="https://www.ubuntu.com/"
SUPPORT_URL="https://help.ubuntu.com/"
BUG_REPORT_URL="https://bugs.launchpad.net/ubuntu/"
PRIVACY_POLICY_URL="https://www.ubuntu.com/legal/terms-and-policies/privacy-policy"
UBUNTU_CODENAME=noble
LOGO=ubuntu-logo
Linux 5.15.167.4-microsoft-standard-WSL2
x86_64Log Fragments
WARNING: DATA RACE
Write at 0x00c00016f400 by goroutine 32:
vitess.io/vitess/go/vt/dbconfigs.(*VaultCredentialsServer).GetUserAndPassword.func1()
credentials.go:206
Previous read at 0x00c00016f400 by goroutine 31:
vitess.io/vitess/go/vt/dbconfigs.(*VaultCredentialsServer).GetUserAndPassword()
credentials.go:212Source: vitessio/vitess