Base solution for your next web application
Ends in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

How to manage concurrncy for post requests #10171


User avatar
0
demo.solaru created

Hello,

  • What is your product version? -- 7.0.0
  • What is your product type (Angular or MVC)? -- Angular
  • What is product framework type (.net framework or .net core)? -- .Net Core

In Aspnetzero application, how should I manage concurrency between request, when same request is posted multiple time .net core end up been creating same record twice.

How should I manage this at .Net Core to prevent multiuple same request.


9 Answer(s)
  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi,

    You can take a look at https://docs.microsoft.com/en-us/ef/core/saving/concurrency.

    Please let us know if you can't manage to implement it.

  • User Avatar
    0
    demo.solaru created

    Hello @ismcagdas

    Is there any other way we can achive database concurrency using IUnitOfWork or with some functionalities from ABP ? It would be great if you can share some example(that may have already been used in application) on how we can do it using aspnetzero code.

    Thank you!

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @demo.solaru

    ABP Framework doesn't offer an out of the box solution for this. Using EF Core's suggested approach is better I think. Have you tried it ? If so, did you face any problems ?

  • User Avatar
    0
    demo.solaru created

    Hello @ismcagdas

    We tried implementing it but because of async transaction (I guess, but not sure) its not working as expcated ... Is there anything we can check in with current unit of work in term of concurrent transactions?

  • User Avatar
    0
    ismcagdas created
    Support Team

    Hi @demo.solaru

    Did you get any errors ? If so, could you share it ? Upgrading your ABP NuGet package version might help here as well.

  • User Avatar
    0
    demo.solaru created

    Hello @ismcagdas!

    Here is how I am trying to implement: error is being catched when exception occurs but still end up being in "message": "An internal error occurred during your request!",

    `public async Task

            await CurrentUnitOfWork.SaveChangesAsync();
    
            if (input.SaveAndSubmit)
                await SubmitInvoice(invoiceId);
        }
        catch (Exception ex)
        {
            if (ex is AbpDbConcurrencyException)
            {
                var inv = await _invoiceRepo.FirstOrDefaultAsync(i => i.InvoiceNumber.ToLower().Equals(input.InvoiceNumber.ToLower()));
                if (inv != null)
                    return inv.Id; // Here it returns the value but it throws the error instead of returning the invoiceId
                throw ex;
            }
            else
                throw ex;
        }
        return invoiceId;
    

    }`

    Response { "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "An internal error occurred during your request!", "details": null, "validationErrors": null }, "unAuthorizedRequest": false, "__abp": true }

    Here actual response should be end up being returning InvoiceId.

  • User Avatar
    0
    musa.demir created

    Hi @demo.solaru

    Can you please share the relavant part of the log file. It is located in aspnet-core\src\[YOURAPPNAME].Web.Host\App_Data\Logs\Logs.txt

  • User Avatar
    0
    demo.solaru created

    Yes, please find attached!

    Edited: URL removed due to sensitive data protection

  • User Avatar
    0
    musa.demir created

    Hi @demo.solaru I removed your url because you shared all of your log files and they may contain sensitive data.

    As you may have noticed, the log files that you have shared contain too many lines. For this reason, it is very difficult to catch the error from there. Can you please reproduce the error and then copy just the relevant part of the log file content which is logged because of that error.