go
data_error
ai_generated
true
rpc error: code = FailedPrecondition desc = resource version mismatch: expected 42, got 41
ID: go/grpc-failed-precondition
80%Fix Rate
83%Confidence
0Evidence
2024-12-02First Seen
Version Compatibility
| Version | Status | Introduced | Deprecated | Notes |
|---|---|---|---|---|
| 1.x | active | — | — | — |
Root Cause
The server rejected the operation because a precondition on the resource state was not met — typically optimistic concurrency control where the client's version/etag is stale relative to the current server state.
generic中文
服务器拒绝了操作,因为资源状态的前置条件未满足——通常是乐观并发控制,客户端携带的版本/etag 相对于服务器当前状态已过时。
Workarounds
-
88% success
Re-fetch the latest resource, apply the mutation to the fresh copy, and retry with the new version: for i := 0; i < 5; i++ { cur, err := client.Get(ctx, &pb.GetReq{Id: id}) if err != nil { return err } cur.Data = newData _, err = client.Update(ctx, &pb.UpdateReq{Id: id, Data: newData, Version: cur.Version}) if status.Code(err) != codes.FailedPrecondition { return err } } -
80% success
Use an ETag/If-Match style conditional request and surface a conflict to the caller when it persists: if status.Code(err) == codes.FailedPrecondition { return ErrConflict // let the caller resolve }
Dead Ends
Common approaches that don't work:
-
90% fail
The version is still stale; the server rejects every identical attempt with the same FailedPrecondition.
-
70% fail
Removing the precondition bypasses concurrency control and risks last-writer-wins data loss.