Environment details
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().
Environment details
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 2ServiceObject.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.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 toServiceObject.prototype.create()to re-runServiceObject.prototype.get()with{ autoCreate: false }if a409 Already Existserror is detected on the call toServiceObject.prototype.create().