Breeze / breeze.js.labs

OFFICIAL Breeze.js Labs package of extensions and utilities for Breeze.js client apps.
MIT License
43 stars 44 forks source link

Calling saveChanges quickly with save queuing can result in a "Concurrent saves not allowed" error #12

Closed byudaniel closed 9 years ago

byudaniel commented 10 years ago

If saveChanges is called very quickly with a complex data model it sometimes throws the error "Concurrent saves not allowed." An entity from the previous saveChanges call is included in the next call to saveChanges with an entityAspect of isBeingSaved = true. It appears that there is some kind of race condition where the previous save promise resolves before isBeingSaved is set to false.

(Using Breeze 1.5.0, Angular 1.0.8, breeze.savequeuing 0.9, breeze.angular 1.1)

RHAD1969 commented 10 years ago

As far as I know is this by design. Enable savequeing is a workaround or you can enable concurrentsaves (not recommended)

byudaniel commented 10 years ago

I have savequeuing enabled, which normally works for similar scenarios, but fails in this particular circumstance. Why is the save promise resolved before isBeingSaved is set to false? It makes the second saveChanges think the entity needs to be saved again when it has not changed.

RHAD1969 commented 10 years ago

I think you should share some code.

wardbell commented 10 years ago

I need a repro. saveQueuing is supposed to prevent this kind of thing.

How I test it

I have a crude way of testing saveQueuing. Usually start with something like the Todo-Angular sample. I put a breakpoint on the Web API TodoController's SaveChanges and run under debug. That breakpoint will simulate a long-running save.

Then in Chrome (or your browser) I set a breakpoint in breeze.saveQueuing.js around line 22 where it tests for if (saveQueuing.isSaving) ....

Then I cause a save (e.g., click a checkbox for a Todo). The first time it sails through (saveQueuing.isSaving is false), the client makes the save call, and debugger breaks on the server in SaveChanges. You trigger another save in the browser (e.g., click it again) and now saveQueuing should queue the save because the server hasn't replied (saveQueuing.isSaving is true).

Let the server continue and all should be well.

What happens for you?

wardbell commented 9 years ago

There are a great number of saveQueueing tests in DocCode ... and saveQueuing is now v.2.0.4. See this StackOverflow post. Would you please try again?

byudaniel commented 9 years ago

With the latest update I cannot duplicate the issue I was having. Thanks for the great update to saveQueuing!