-
Notifications
You must be signed in to change notification settings - Fork 44
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Transaction "add"s are not multi-thread safe #295
Comments
seems like we may want to at minimum document this. I am unsure if they are intended to be used in this way and if there aren't other issues or not. @kolea2 is multithread usage of a client a supported scenario for java clients? |
@kolea2 ping |
I was able to replicate this using this code. A transaction getting modified multiple times through 4 threads. To successfully replicate, this needs to run in loop as it's nondeterministic behaviour. Digging deeper into this,
There are higher chances that I feel this is by design as the early developers of the library wanted to access the For now, documenting the thread unsafe behaviour of Transaction, Batch and DatastoreBatchWriter classes to have users be aware of the existing behaviour. |
The
add(entity)
method in aTransaction
object is not multi-thread safe. Other methods (e.g. put, delete) may also not be safe but we have traced a failure in our server specifically toadd
. Our server uses Scala Futures and so uses multiple threads of execution.The particular scenario we tracked down was in our new user creation processing where we add 4 entities in a transaction. However there was a probability that one of the entities didn't get saved. It wasn't always the same entity kind that "disappeared". We traced this by adding debug logging after the 'add' calls that shows the
add
s successfully completing - but subsequent processing would find one of the entities missing. We did note that it always seemed to be just one entity missing and when an entity did go missing it seemed to be the first entity kind to be added (thread execution order was not consistent across invocations).We added
synchronize
on each of our DataStore calls and haven't encountered this issue since. So at a minimum this issue can serve as a warning to others. Maybe a note could be added to the documentation. But we are also patiently waiting for issue #22 (async support) to be implemented and would hope that explicit synchronization to not be needed.The text was updated successfully, but these errors were encountered: