-
Notifications
You must be signed in to change notification settings - Fork 652
Description
Environment details
- OS: Ubuntu 14.04
- Node.js version: v6.9.5
- npm version: 3.10.10
- google-cloud-node version: google-cloud@0.46.1 @google-cloud/pubsub@0.8.0
Steps to reproduce
This can be reproduced under specific conditions when using the "get or create" functionality described in ServiceObject.protoype.get() with { autoCreate: true }. I discovered it while using the pubsub API. If you run 2 ServiceObject.protoype.get() at the same time with the same arguments for a resource that does not exist prior, it is possible for one to succeed and the other to fail. This does not seem like intended behavior to me.
- Request 1 -> get
- Request 2 -> get
- Request 1 <- 404 Not Found
- Request 2 <- 404 Not Found
- Request 1 -> create
- Request 1 <- 200 OK
- Request 2 -> create
- Request 2 <- 409 Conflict
If these requests occur in different orders it is possible for both to pass or one to fail and the other pass.
Thoughts?
I have a proposed fix that modifies the ServiceObject.prototype.get() when { autoCreate: true } that wraps the call to ServiceObject.prototype.create() to re-run ServiceObject.prototype.get() with { autoCreate: false } if a 409 Already Exists error is detected on the call to ServiceObject.prototype.create().