googleapis / googleapis/google-cloud-go
datastore: Transaction appears to be unsafe to use concurrently
- Dominant language
- Go
- Stars
- 4.5k
- Forks
- 1.6k
- Avg merge
- 1d 13h
- Merged PRs (30d)
- 109
Description
**Client**
Datastore
**Environment**
Any
**Go Environment**
Any
**Code**
e.g. https://github.com/googleapis/google-cloud-go/blob/master/datastore/transaction.go#L311
At least the `mutations` field is unguarded by any synchronization mechanism, but the `pending` field is also suspect.
This is a seeming departure from the GAE version of the library e.g. (https://github.com/golang/appengine/blob/master/datastore/datastore.go#L351) where Put requests translated directly to a (concurrency safe) RPC which included the transaction ID as part of the RPC. Direct translations of older GAE code to use the new datastore library could introduce subtle concurrency bugs.
I believe adding mutex would be sufficient to protect the Transaction struct's integrity... however if this is infeasible, it would be great to explicitly call out on Transaction that it is NOT concurrency-safe.
Contributor guide
Assessment
This issue has not been assessed yet.