Starts in:
2 DAYS
6 HRS
53 MIN
6 SEC
Starts in:
2 D
6 H
53 M
6 S
Open Closed

Concurrency issue #8122


User avatar
0
priyankasynapxe created

ABP Framework version: v8.1.1

UI Type:React

Database System: EF Core (SQL Server)

Tiered (for MVC) or Auth Server Separated (for Angular): yes

Exception message and full stack trace: NA

Steps to reproduce the issue: NA

Hi, I have recently added a new table but sometimes I found below error in log file. Please help me to know the rott cause and way to fix it.

Thanks.


13 Answer(s)
  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    you can check the document https://abp.io/docs/latest/framework/infrastructure/concurrency-check

  • User Avatar
    0
    priyankasynapxe created

    Hi,

    you can check the document
    https://abp.io/docs/latest/framework/infrastructure/concurrency-check

    Hi, Thank you for sharing the link, I checked it, but I have one more question, I have one more table and I'm doing same update on both table but for the other table I never faced concurrency issue even though I don't have ConcurrencyStamp in other table. Why both tables are behaving differently?

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    Hi,

    Because there is no ConcurrencyStamp in the other table, so there is no concurrency check.

  • User Avatar
    0
    priyankasynapxe created

    Hi,

    Because there is no ConcurrencyStamp in the other table, so there is no concurrency check.

    Hi, In both table I don't have ConcurrencyStamp but issue is encountered only in for 1 table, even though I'm doing same operation on both tables.

  • User Avatar
    0
    liangshiwei created
    Support Team Fullstack Developer

    can you share your entity class code?

  • User Avatar
    0
    priyankasynapxe created

    can you share your entity class code?

    This is my class where I'm getting error

    using eFC.Patients; using eFC.CodeLookUps; using System; using System.Linq; using System.Collections.Generic; using System.Collections.ObjectModel; using Volo.Abp.Domain.Entities; using Volo.Abp.Domain.Entities.Auditing; using Volo.Abp.MultiTenancy; using JetBrains.Annotations;

    using Volo.Abp;

    namespace eFC.EncounterMovementPlaceholders { public class EncounterMovementPlaceholder : FullAuditedAggregateRoot<long> { [NotNull] public virtual string IdentificationText { get; set; }

        [CanBeNull]
        public virtual long? InstitutionId { get; set; }
    
        [CanBeNull]
        public virtual DateTime? AdmissionDate { get; set; }
    
        [CanBeNull]
        public virtual DateTime? DischargedDate { get; set; }
    
        [CanBeNull]
        public virtual string InstitutionCode { get; set; }
    
        [CanBeNull]
        public virtual string MsgType { get; set; }
    
        [CanBeNull]
        public virtual string HAR { get; set; }
    
        [CanBeNull]
        public virtual string CIPInd { get; set; }
    
        [CanBeNull]
        public virtual string ReferralHospital { get; set; }
    
        [CanBeNull]
        public virtual string ReferralType { get; set; }
    
        [CanBeNull]
        public virtual string VIPInd { get; set; }
    
        [CanBeNull]
        public virtual string VVIPInd { get; set; }
    
        [CanBeNull]
        public virtual string OpReferralHospital { get; set; }
    
        [CanBeNull]
        public virtual string OpReferralType { get; set; }
    
        [CanBeNull]
        public virtual string FCStatus { get; set; }
    
        [CanBeNull]
        public virtual string AccountStatus { get; set; }
    
        [CanBeNull]
        public virtual string OpVisitTypeDescription { get; set; }
    
        [CanBeNull]
        public virtual string OpVisitType_Code { get; set; }
    
        [CanBeNull]
        public virtual string Accident_Code { get; set; }
    
        [CanBeNull]
        public virtual string Accomodation_Code { get; set; }
    
        [CanBeNull]
        public virtual string AdmissionType_Code { get; set; }
    
        [CanBeNull]
        public virtual string ApptCat_Code { get; set; }
    
        [CanBeNull]
        public virtual string LevelOfCare_Code { get; set; }
        [CanBeNull]
        public virtual long ?OpVisitTypeID { get; set; }
    
        [CanBeNull]
        public virtual string PointOfCare_Code { get; set; }
    
        [CanBeNull]
        public virtual string Specialty_Code { get; set; }
    
        [CanBeNull]
        public virtual string SubDocType_Code { get; set; }
    
        [CanBeNull]
        public virtual string InstitutionType { get; set; }
    
        [CanBeNull]
        public virtual string DischargeLocation { get; set; }
    
        public virtual long? EncounterId { get; set; }
    
        [CanBeNull]
        public virtual string PendingEventId { get; set; }
    
        [CanBeNull]
        public virtual string PendingRecordId { get; set; }
        public long? PatientId { get; set; }
        public long? AccomodationCode { get; set; }
        public long? AdmissionTypeId { get; set; }
        public long? LevelOfcareId { get; set; }
        public long? SubDocType { get; set; }
        public long? SpecialtyId { get; set; }
        public long? ExternalSourceId { get; set; }
        public long? Status { get; set; }
        public long? AccidentCode { get; set; }
        public long? AccomodationCodeReason { get; set; }
        public long? ApptCatCode { get; set; }
        public long? DischargeDisposition { get; set; }
        public long? LateDischargeReason { get; set; }
        public long? PointOfCare { get; set; }
        public long? TransferReason { get; set; }
        public long? VisitType { get; set; }
        public long? ResidentialStatus { get; set; }
    
        public EncounterMovementPlaceholder()
        {
    
        }
    
        public EncounterMovementPlaceholder(long? patientId, long? accomodationCode, long? admissionTypeId, long? levelOfcareId, long? subDocType, long? specialtyId, long? externalSourceId, long? status, long? accidentCode, long? accomodationCodeReason, long? apptCatCode, long? dischargeDisposition, long? lateDischargeReason, long? pointOfCare, long? transferReason, long? visitType, long? residentialStatus, string identificationText, long institutionId, DateTime admissionDate, DateTime dischargedDate, long opVisitTypeID, string institutionCode = null, string msgType = null, string hAR = null, string cIPInd = null, string referralHospital = null, string referralType = null, string vIPInd = null, string vVIPInd = null, string opReferralHospital = null, string opReferralType = null, string fCStatus = null, string accountStatus = null, string opVisitTypeDescription = null, string opVisitType_Code = null, string accident_Code = null, string accomodation_Code = null, string admissionType_Code = null, string apptCat_Code = null, string levelOfCare_Code = null, string pointOfCare_Code = null, string specialty_Code = null, string subDocType_Code = null, string institutionType = null, string dischargeLocation = null, long? encounterId = null, string pendingEventId = null, string pendingRecordId = null)
        {
    
            Check.NotNull(identificationText, nameof(identificationText));
            Check.Length(identificationText, nameof(identificationText), EncounterMovementPlaceholderConsts.IdentificationTextMaxLength, EncounterMovementPlaceholderConsts.IdentificationTextMinLength);
            Check.Length(msgType, nameof(msgType), EncounterMovementPlaceholderConsts.MsgTypeMaxLength, 0);
            Check.Length(hAR, nameof(hAR), EncounterMovementPlaceholderConsts.HARMaxLength, 0);
            Check.Length(cIPInd, nameof(cIPInd), EncounterMovementPlaceholderConsts.CIPIndMaxLength, 0);
            Check.Length(referralHospital, nameof(referralHospital), EncounterMovementPlaceholderConsts.ReferralHospitalMaxLength, 0);
            Check.Length(referralType, nameof(referralType), EncounterMovementPlaceholderConsts.ReferralTypeMaxLength, 0);
            Check.Length(vIPInd, nameof(vIPInd), EncounterMovementPlaceholderConsts.VIPIndMaxLength, 0);
            Check.Length(vVIPInd, nameof(vVIPInd), EncounterMovementPlaceholderConsts.VVIPIndMaxLength, 0);
            Check.Length(opReferralHospital, nameof(opReferralHospital), EncounterMovementPlaceholderConsts.OpReferralHospitalMaxLength, 0);
            Check.Length(opReferralType, nameof(opReferralType), EncounterMovementPlaceholderConsts.OpReferralTypeMaxLength, 0);
            Check.Length(fCStatus, nameof(fCStatus), EncounterMovementPlaceholderConsts.FCStatusMaxLength, 0);
            Check.Length(accountStatus, nameof(accountStatus), EncounterMovementPlaceholderConsts.AccountStatusMaxLength, 0);
            Check.Length(opVisitTypeDescription, nameof(opVisitTypeDescription), EncounterMovementPlaceholderConsts.OpVisitTypeDescriptionMaxLength, 0);
            Check.Length(opVisitType_Code, nameof(opVisitType_Code), EncounterMovementPlaceholderConsts.OpVisitType_CodeMaxLength, 0);
            Check.Length(accident_Code, nameof(accident_Code), EncounterMovementPlaceholderConsts.Accident_CodeMaxLength, 0);
            Check.Length(accomodation_Code, nameof(accomodation_Code), EncounterMovementPlaceholderConsts.Accomodation_CodeMaxLength, 0);
            Check.Length(admissionType_Code, nameof(admissionType_Code), EncounterMovementPlaceholderConsts.AdmissionType_CodeMaxLength, 0);
            Check.Length(apptCat_Code, nameof(apptCat_Code), EncounterMovementPlaceholderConsts.ApptCat_CodeMaxLength, 0);
            Check.Length(levelOfCare_Code, nameof(levelOfCare_Code), EncounterMovementPlaceholderConsts.LevelOfCare_CodeMaxLength, 0);
            Check.Length(pointOfCare_Code, nameof(pointOfCare_Code), EncounterMovementPlaceholderConsts.PointOfCare_CodeMaxLength, 0);
            Check.Length(specialty_Code, nameof(specialty_Code), EncounterMovementPlaceholderConsts.Specialty_CodeMaxLength, 0);
            Check.Length(subDocType_Code, nameof(subDocType_Code), EncounterMovementPlaceholderConsts.SubDocType_CodeMaxLength, 0);
            Check.Length(institutionType, nameof(institutionType), EncounterMovementPlaceholderConsts.InstitutionTypeMaxLength, 0);
            Check.Length(dischargeLocation, nameof(dischargeLocation), EncounterMovementPlaceholderConsts.DischargeLocationMaxLength, 0);
            Check.Length(pendingEventId, nameof(pendingEventId), EncounterMovementPlaceholderConsts.PendingEventIdMaxLength, 0);
            Check.Length(pendingRecordId, nameof(pendingRecordId), EncounterMovementPlaceholderConsts.PendingRecordIdMaxLength, 0);
            IdentificationText = identificationText;
            InstitutionId = institutionId;
            AdmissionDate = admissionDate;
            DischargedDate = dischargedDate;
            OpVisitTypeID = opVisitTypeID;
            InstitutionCode = institutionCode;
            MsgType = msgType;
            HAR = hAR;
            CIPInd = cIPInd;
            ReferralHospital = referralHospital;
            ReferralType = referralType;
            VIPInd = vIPInd;
            VVIPInd = vVIPInd;
            OpReferralHospital = opReferralHospital;
            OpReferralType = opReferralType;
            FCStatus = fCStatus;
            AccountStatus = accountStatus;
            OpVisitTypeDescription = opVisitTypeDescription;
            OpVisitType_Code = opVisitType_Code;
            Accident_Code = accident_Code;
            Accomodation_Code = accomodation_Code;
            AdmissionType_Code = admissionType_Code;
            ApptCat_Code = apptCat_Code;
            LevelOfCare_Code = levelOfCare_Code;
            PointOfCare_Code = pointOfCare_Code;
            Specialty_Code = specialty_Code;
            SubDocType_Code = subDocType_Code;
            InstitutionType = institutionType;
            DischargeLocation = dischargeLocation;
            EncounterId = encounterId;
            PendingEventId = pendingEventId;
            PendingRecordId = pendingRecordId;
            PatientId = patientId;
            AccomodationCode = accomodationCode;
            AdmissionTypeId = admissionTypeId;
            LevelOfcareId = levelOfcareId;
            SubDocType = subDocType;
            SpecialtyId = specialtyId;
            ExternalSourceId = externalSourceId;
            Status = status;
            AccidentCode = accidentCode;
            AccomodationCodeReason = accomodationCodeReason;
            ApptCatCode = apptCatCode;
            DischargeDisposition = dischargeDisposition;
            LateDischargeReason = lateDischargeReason;
            PointOfCare = pointOfCare;
            TransferReason = transferReason;
            VisitType = visitType;
            ResidentialStatus = residentialStatus;
        }
    
    }
    

    }

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    The EncounterMovementPlaceholder inherit fromFullAuditedAggregateRoot and AggregateRoot

    So, your entity has a ConcurrencyStamp property.

    https://github.com/abpframework/abp/blob/rel-9.0/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs#L18

    Can you share the code that caused the exception?

  • User Avatar
    0
    priyankasynapxe created

    hi

    The EncounterMovementPlaceholder inherit fromFullAuditedAggregateRoot and AggregateRoot

    So, your entity has a ConcurrencyStamp property.

    https://github.com/abpframework/abp/blob/rel-9.0/framework/src/Volo.Abp.Ddd.Domain/Volo/Abp/Domain/Entities/AggregateRoot.cs#L18

    Can you share the code that caused the exception?

    below is the function where I'm updating this table and getting exception

    private async Task<bool> UpdateFCStatus(IList<long> encounterIds, long fcId, long fcModeId,int completedCount = 0, draftCount = 0, exemptedCount = 0)
    {
        foreach (long encounterRelation in encounterIds)
        {
            List<FinancialCounseling> fcList = await _financialCounselingRepository.GetEncounterFCRealtionAsync(encounterRelation);
                 
            string fcStatus = string.Format("Completed({0}),Draft({1}),Exempted({2})", completedCount.ToString(), draftCount.ToString(), exemptedCount.ToString());
    
            var encounterData = await _encounterRepository.GetAsync(encounterRelation);
            encounterData.FCStatus = fcStatus;
            await _encounterRepository.UpdateAsync(encounterData);
    
            //Updating encounter status in Encounter placeholder table
            **var encounterPlaceHolderData = await _encounterMovementPlaceholderRepository.GetEncounterMovementPlaceholderByEncounterIdAsync(encounterRelation);
            if (encounterPlaceHolderData != null)
            {
                encounterPlaceHolderData.FCStatus = fcStatus;
                await _encounterMovementPlaceholderRepository.UpdateAsync(encounterPlaceHolderData);
            }**
        }
        return true;
    }
    
  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    hi

    You can try to catch the exception and ignore or retry.

    private async Task<bool> UpdateFCStatus(IList<long> encounterIds, long fcId, long fcModeId,int completedCount = 0, draftCount = 0, exemptedCount = 0)
    {
        try
        {
            using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: UnitOfWorkManager.Current?.Options.IsTransactional ?? false))
            {
                // your code
                await uow.CompleteAsync();
            }
        }
        catch (AbpDbConcurrencyException e)
        {
            ///
        }
    }
    
  • User Avatar
    0
    priyankasynapxe created

    hi

    You can try to catch the exception and ignore or retry.

    private async Task<bool> UpdateFCStatus(IList<long> encounterIds, long fcId, long fcModeId,int completedCount = 0, draftCount = 0, exemptedCount = 0) 
    { 
        try 
        { 
            using (var uow = UnitOfWorkManager.Begin(requiresNew: true, isTransactional: UnitOfWorkManager.Current?.Options.IsTransactional ?? false)) 
            { 
                // your code 
                await uow.CompleteAsync(); 
            } 
        } 
        catch (AbpDbConcurrencyException e) 
        { 
            /// 
        } 
    } 
    

    this will not prevent concurrency issue but it's just if concurrency issue comes it will retry, is my understanding correct?

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    Yes, the entity has the ConcurrencyStamp , so there will be an AbpDbConcurrencyException.

    see https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=data-annotations

  • User Avatar
    0
    priyankasynapxe created

    Yes, the entity has the ConcurrencyStamp , so there will be an AbpDbConcurrencyException.

    see https://learn.microsoft.com/en-us/ef/core/saving/concurrency?tabs=data-annotations

    ok, thank you. will try.

  • User Avatar
    0
    maliming created
    Support Team Fullstack Developer

    : )

Made with ❤️ on ABP v9.1.0-preview. Updated on November 20, 2024, 13:06