Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Critical Bug Fix | Nested generated Distributed Event is not being published #22054

Closed
wants to merge 1 commit into from

Conversation

alyssonrpg
Copy link

@alyssonrpg alyssonrpg commented Jan 31, 2025

Description

This pull request fixes a bug related to the publication of distributed events when they are generated in a nested manner during the completion of a UnitOfWork.

Scenario in Which the Bug Occurs

  1. Initiating a UnitOfWork: A new UnitOfWork is started.

  2. Appending Events: Both a Local Event and a Distributed Event are appended to the UnitOfWork.

  3. Completing the UnitOfWork: The CompleteAsync method is called on the UnitOfWork.

  4. Handling the Local Event: The ILocalEventHandler for the local event is invoked.

  5. Nested Generation of a Distributed Event: During the execution of the ILocalEventHandler, a new Distributed Event is generated in a nested manner.

Identified Issue

  • The Distributed Event generated in step 5 is not being published to the IUnitOfWorkEventPublisher.
  • This occurs because the loop that publishes local and distributed events in UnitOfWork.CompleteAsync() is not correctly handling this nestedly generated event.
  • As a result, there is a critical miss in event publication, leading to potential inconsistencies in the system and affecting functionalities that rely on the proper propagation of distributed events.

Checklist

  • I fully tested it as developer / designer and created unit / integration tests
  • I documented it (or no need to document or I will create a separate documentation issue)

How to Test It?

I have included a unit test in this pull request: Volo.Abp.Uow.UnitOfWork_Event_Publisher_Tests that tests this scenario. To observe the bug, simply run this test with the previous version of UnitOfWork.cs to see the issue occur.

… a nested manner during the completion of unit of works.

Previously, if the event was generated in a nested manner, the publication was not happening.
@CLAassistant
Copy link

CLAassistant commented Jan 31, 2025

CLA assistant check
All committers have signed the CLA.

@alyssonrpg alyssonrpg changed the title Bug Fix | Nested generated Distributed Event is not being published Critical Bug Fix | Nested generated Distributed Event is not being published Jan 31, 2025
@maliming maliming self-requested a review February 1, 2025 02:58
maliming added a commit that referenced this pull request Feb 1, 2025
@maliming
Copy link
Member

maliming commented Feb 1, 2025

Thanks @alyssonrpg

I have moved the code to the rel-9.0 branch. The dev branch is targeted to 9.2.

#22056

@alyssonrpg
Copy link
Author

alyssonrpg commented Feb 1, 2025

Thanks @alyssonrpg

I have moved the code to the rel-9.0 branch. The dev branch is targeted to 9.2.

#22056

@maliming Nice! However, I'd like to suggest using the unit test I've written in this PR as well. The test in PR #22056 would fail to identify this bug.

The bug happens when a local event handler, invoked within that loop, attempts to publish a new distributed event.

@maliming
Copy link
Member

maliming commented Feb 1, 2025

@alyssonrpg
Copy link
Author

alyssonrpg commented Feb 1, 2025

hi @alyssonrpg I update the test code. It is the same as yours.

https://github.com/abpframework/abp/pull/22056/files#diff-fc97f9f91f2d3caf7c4ea9d078dadd373d3953ccfddd26b50793c5180ec0ef80R182-R226

@maliming sorry, my bad. I am reading the code on a phone screen and I missed a detail. The test is alright

@maliming maliming closed this Feb 1, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants