backend/http: Return existing lock info from backend on conflict (#38144)

* Return existing lock info from http state backend on conflict

* Remove info from LockError if failed to read or unmarshal

* Add change to .changes
This commit is contained in:
Nicholas Ngai 2026-02-18 09:00:54 -08:00 committed by GitHub
parent d92915a29a
commit 5e4cfd42fa
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 6 additions and 5 deletions

View file

@ -0,0 +1,3 @@
kind: BUG FIXES
body: 'backend: Return conflicting lock info from HTTP backend instead of the lock that failed to be taken'
time: 2026-02-10T11:39:30.00000-08:00

View file

@ -105,20 +105,18 @@ func (c *httpClient) Lock(info *statemgr.LockInfo) (string, error) {
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return "", &statemgr.LockError{
Info: info,
Err: fmt.Errorf("HTTP remote state already locked, failed to read body"),
Err: fmt.Errorf("HTTP remote state already locked, failed to read body"),
}
}
existing := statemgr.LockInfo{}
err = json.Unmarshal(body, &existing)
if err != nil {
return "", &statemgr.LockError{
Info: info,
Err: fmt.Errorf("HTTP remote state already locked, failed to unmarshal body"),
Err: fmt.Errorf("HTTP remote state already locked, failed to unmarshal body"),
}
}
return "", &statemgr.LockError{
Info: info,
Info: &existing,
Err: fmt.Errorf("HTTP remote state already locked: ID=%s", existing.ID),
}
default: