SAP / openui5

OpenUI5 lets you build enterprise-ready web applications, responsive to all devices, running on almost any browser of your choice.
http://openui5.org
Apache License 2.0
2.96k stars 1.24k forks source link

v2.oDataModel CREATE $batch handling sends same CREATE requests multiple times in multiple $batch requests due to timing issues #3901

Closed dominikfeininger closed 9 months ago

dominikfeininger commented 11 months ago

I experience a strange race condition issue with oDataModel V2 and $batch requests.

The app saves new entries of an entity by user input or automatically. Technically the model sends multiple CREATE requests using createEntry and submitChanges consecutively. This works most of the time fine.

Sometimes a second $batch request containing the latest and the previous (still ongoing) CREATE is send due the last call was not finished yet. Since it is a create the SAP BE returns an duplicate IDs error.

OpenUI5 version: 1.102.17

What is the expected result?

What happens instead?

IlianaB commented 11 months ago

Hello @dominikfeininger ,

If possible, can you provide a reproducible sample or at least share with us parts of your code, which lead to a different than expected behavior?

Regards, Iliana

dominikfeininger commented 11 months ago

Hi, I will try to provide an example, but this will be quite complicated due to the need of a backend service.

flovogt commented 11 months ago

If the issue appears in a SAP system, you might create an SAP support incident so the developers can have a look at your system.

dominikfeininger commented 10 months ago

Hello @dominikfeininger ,

If possible, can you provide a reproducible sample or at least share with us parts of your code, which lead to a different than expected behavior?

Regards, Iliana

Hi, you can find a basic example here: https://github.com/dominikfeininger/OdataV2BatchIssue. Even though the northwind service does not accept the POST you can see the duplicate batching in the network tab if you press the add Itembutton more often.

flovogt commented 10 months ago

Hi @dominikfeininger, thanks for the sample. I have created an internal incident DINC0028400. The responsible team will analyze your issue and post any further updates here in github.

StSche commented 9 months ago

Hi @dominikfeininger,

We have analyzed the problem you have described and come to the following result:

  1. Unfortunately, the sample application of you is not a valid example of the described problem because the northwind service does not accept the POST request due to the following error: "id-1704358929641-45' is not a valid value for the 'Content-ID' header. In batch requests, the 'Content-ID' header must be an integer value." At this point, however, the northwind service does not behave in accordance with specifications, see: https://help.sap.com/doc/5890d27be418427993fafa6722cdc03b/Cloud/en-US/OdataV2.pdf, 2.2.7.6.1.1 Referencing Requests in a Change Set https://www.rfc-editor.org/rfc/inline-errata/rfc2045.html,

    1. Content ID Header Field Since requests that fail are repeated until they are either passed through or deleted by the application, the behavior is expected at this point.
  2. As it looks to me, in your case v2.ODataModel.submitChanges is called for the second time, while the first v2.ODataModel.submitChanges has not yet been processed. This leads to the error you described. One way to avoid this problem may be to disable the "save" button which triggers v2.ODataModel.submitChanges until the submitChanges from a former click on this button has been processed. This could be done, for example, using the success or error handler of v2.ODataModel.submitChanges. However, this is the responsibility of the application.

To further analyze the error reason, you can try the following. Set a breakpoint in v2.ODataModel.submitChanges and see where the second call comes from in the event of an error.