Open Closed

Concurrency issues after upgrading from 8.2.3 to 8.3.4 #9179


User avatar
0
neethucp created

Hi,

We're encountering concurrency errors when making parallel requests, even when the entity remains unmodified. Upon investigation, we found that the last modification time and concurrency stamp are updated despite no other property changes. It appears that using no-tracking queries might be the only viable solution. However, we're wondering why the SaveChanges method updates the modification time and concurrency stamp even when the entity state is unchanged. Since our queries were generated using ABP Suite, modifying all of them to use no-tracking would require significant effort, making it an impractical option at this stage. Could you assist us in resolving this issue?


25 Answer(s)
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We're encountering concurrency errors when making parallel requests, even when the entity remains unmodified.

    What entity changed?

    Can you share some code?


    The entity will be changed if its child entities have changed.

    AbpEntityChangeOptions => PublishEntityUpdatedEventWhenNavigationChanges

    Thanks.

  • User Avatar
    0
    neethucp created

    We are retrieving configuration data from the database and using it to create an entity. For instance, we query the task type from the database and utilize its configuration to create a task item and insert it. However, when we attempt to insert the task, we encounter the following concurrency exception:

    There is an entry which is not saved due to a concurrency exception: TaskType {Id: 8c6fb91c-177b-d1a0-97ea-3a17acd7ce44} Modified FK {AdviceTypeId: <null>} FK {TaskRequestTypeId: c5522fb7-64df-20b1-00af-3a17acd79a32}

    We have not modified any details of the task type in the API. The issue is resolved when we use IReadOnlyRepository to fetch the task type. However, given that we have numerous queries spread throughout the system, modifying them all is not a feasible solution at this stage.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Can you share the two entity class code?

    TaskType and Task


    You can also Using the DisableTracking extension method to do the same thing as IReadOnlyRepository

    https://abp.io/docs/9.0/framework/architecture/domain-driven-design/repositories#repository-extension-methods-for-change-tracking

    Thanks.

  • User Avatar
    0
    neethucp created

    The problem is we will have to disable tracking in a lot of places.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We will publish an event and update the entity when a navigation property of an entity has changed

    But you can disable it for a specific entity.

    Please try to add MyAbpEfCoreNavigationHelper to your EF Core project.

    using Microsoft.EntityFrameworkCore.ChangeTracking;
    using Volo.Abp.DependencyInjection;
    using Volo.Abp.EntityFrameworkCore.ChangeTrackers;
    using Volo.Abp.OpenIddict.Tokens;
    
    [Dependency(ReplaceServices = true)]
    [ExposeServices(typeof(AbpEfCoreNavigationHelper))]
    public class MyAbpEfCoreNavigationHelper : AbpEfCoreNavigationHelper
    {
        public override void ChangeTracker_Tracked(object? sender, EntityTrackedEventArgs e)
        {
            if (e.Entry.Entity.GetType() == typeof(TaskType))
            {
                return;
            }
    
            base.ChangeTracker_Tracked(sender, e);
        }
    
        public override void ChangeTracker_StateChanged(object? sender, EntityStateChangedEventArgs e)
        {
            if (e.Entry.Entity.GetType() == typeof(TaskType))
            {
                return;
            }
    
            base.ChangeTracker_StateChanged(sender, e);
        }
    }
    
    
    

    And we add a selector to ignore some entities >= 9.1.1

    https://github.com/abpframework/abp/pull/22315/files

  • User Avatar
    0
    neethucp created

    Do you mean that when task item is inserted, task type will be modified? The following is the logs. The exception happened as the concurrency stamp got modified by a parallel request to create another task.

    We have a lot of entities similar to this, so should we configure this for every entity?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We have a lot of entities similar to this, so should we configure this for every entity?

    You can ignore them(TaskTypes) in MyAbpEfCoreNavigationHelper

    Or set PublishEntityUpdatedEventWhenNavigationChanges to false of AbpEntityChangeOptions to keep the previous behavior.

  • User Avatar
    0
    neethucp created

    Hi,

    I have tried upgrading v9.1.0 using abpupdate but couldn't find IgnoredNavigationEntitySelectors property. Is there a newer version where this property is available?

    We have a microservices solution and heavily rely on events, so we are not confident setting PublishEntityUpdatedEventWhenNavigationChanges to false as it was defaulted to true in the previous version. Looks like the change to update the modification time came from this PR. https://github.com/abpframework/abp/pull/20012/files#diff-33b18ab38146b084012e294cf1639bbce7e8cc903594b83e3beee5b49193af1f. We don't want to disable PublishEntityUpdatedEventWhenNavigationChanges as this might impact other areas of our project.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Please update the package to 9.1.1. The IgnoredNavigationEntitySelectors will be available.

    Thanks.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    abp update --version 9.1.1

    Or

    You can search and replace the abp & Volo package version in *.csproj files globally.

    ABP & VOLO to 9.1.1 LeptonX to 4.1.1

  • User Avatar
    0
    neethucp created

    Thank you. We will try updating to 9.1.1.

    Will this change in the PR(https://github.com/abpframework/abp/pull/20012/files#diff-33b18ab38146b084012e294cf1639bbce7e8cc903594b83e3beee5b49193af1f.) result in updating the modification time and concurrency stamp of all ef core tracked entities even if the navigation properties are not updated?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Framework will skip it : https://github.com/abpframework/abp/blob/rel-9.1/framework/src/Volo.Abp.EntityFrameworkCore/Volo/Abp/EntityFrameworkCore/AbpDbContext.cs#L274

    You can try it.

    Thanks.

  • User Avatar
    0
    neethucp created

    Ignoring all entities affected by this issue is not a viable option. For instance, when creating a new version of an entity object, we first load the existing entity from the database, copy its details, and insert the new object into the database. Since the new version might have no direct relationship to the original entity, would this process still trigger an update to the concurrency stamp of the existing entity? We don't want to ignore the entity because we may want to trigger events when navigation properties change for that entity.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    Since the new version might have no direct relationship to the original entity, would this process still trigger an update to the concurrency stamp of the existing entity?

    No, it will only trigger for the navigation property.

  • User Avatar
    0
    neethucp created

    Hi, we implemented the solution for task type successfully. However, as I previously mentioned, with approximately 20 microservices and hundreds of entities, manually configuring each one and retesting is not feasible at this stage. We urgently need a solution for this, as our deadlines are fast approaching.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    we implemented the solution for task type successfully.

    Are you using IgnoredNavigationEntitySelectors?

  • User Avatar
    0
    neethucp created

    yes, we tested by upgrading to 9.1.1 and ignored TaskType

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    We can only modify the code to resolve this issue. There is no simpler way.

    hundreds of entities

    Only entities with 1-n relationships may get concurrency exceptions. Not all entities.

  • User Avatar
    0
    neethucp created

    We tried the following code to ignore all entites.

    Configure<AbpEntityChangeOptions>(options => { options.IgnoredNavigationEntitySelectors.Add("DisableAllEntity", _ => true); });

    Do you think this could have any unintended consequences?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    You can consider handling concurrent exceptions rather than disabling them. You can catch exceptions and then retry.

  • User Avatar
    0
    neethucp created

    But I don't want to update task type when task item is inserted or modified as TaskType is an AggregateRoot. I believe the concurrency stamp and modification time of an aggregate root should not be updated when a related aggregate root changes.

    This adjustment would be reasonable if the child entity were an AuditedEntity. For instance, in the case of an Order and Order Items, it might be necessary to update the modification time and concurrency stamp of the Order when an Order Item is inserted or modified. In such scenarios, I would extend OrderItem from AuditedEntity rather than AuditedAggregateRoot.

    I believe this is a bug with abp code.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can override the PublishEventsForChangedEntityOnSaveChangeAsync of AbpDbContext and skip these lines.

    if (entityEntry.State == EntityState.Unchanged)
    {
        ApplyAbpConceptsForModifiedEntity(entityEntry, true);
    }
    

    I will add an option to skip this in the next version.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    I will add an option to skip this in the next version.

    https://github.com/abpframework/abp/pull/22752

  • User Avatar
    0
    neethucp created

    I really appreciate your swift reply! Is there a scheduled timeline for its release?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    It will be available on abp 9.2.0.

    9.2.0 due by April 29, 2025

Boost Your Development
ABP Live Training
Packages
See Trainings
Mastering ABP Framework Book
The Official Guide
Mastering
ABP Framework
Learn More
Mastering ABP Framework Book
Made with ❤️ on ABP v10.0.0-preview. Updated on July 11, 2025, 11:35