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

[Fix] MultiSyncModeSelector.Changed event propagation being blocked by SyncFeed #6529

Merged

Conversation

smartprogrammer93
Copy link
Contributor

@smartprogrammer93 smartprogrammer93 commented Jan 12, 2024

Fixes #6481

Changes

  • SyncFeed's Intialize method takes a while. Call to it made async.
  • Log messages are only printed out once SyncFeed finishes initialization.

Types of changes

What types of changes does your code introduce?

  • Bugfix (a non-breaking change that fixes an issue)
  • New feature (a non-breaking change that adds functionality)
  • Breaking change (a change that causes existing functionality not to work as expected)
  • Optimization
  • Refactoring
  • Documentation update
  • Build-related changes
  • Other: Description

Testing

Requires testing

  • Yes
  • No

If yes, did you write tests?

  • Yes
  • No

Documentation

Requires documentation update

  • Yes
  • No

Requires explanation in Release Notes

  • Yes
  • No

@smartprogrammer93 smartprogrammer93 changed the title [Fix] MultiSyncModeSelector.changed event propagation being blocked by other event handlers [Fix] MultiSyncModeSelector.Changed event propagation being blocked by other event handlers Jan 12, 2024
Copy link
Member

@benaadams benaadams left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting solution! 😊

Copy link
Member

@LukaszRozmej LukaszRozmej left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this is solving the issue? What is the technical cause of the issue? If someone is blocking the Changed handler, maybe that subscription needs to be parallelized and not the invocation?

Comment on lines 284 to 288
if (Changed is not null)
{
Parallel.ForEach(Changed.GetInvocationList(),
deleg => deleg.DynamicInvoke(this, args));
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it should not happen, but in theory pattern is to do a local copy to avoid NullReferenceException and be thread-safe:

https://stackoverflow.com/questions/33166143/local-copy-of-event

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

😲 You learn something every day

@asdacap
Copy link
Contributor

asdacap commented Jan 13, 2024

What was the problem?

@benaadams
Copy link
Member

benaadams commented Jan 13, 2024

What was the problem?

Multiple events subscribed to the event; important one is second, first one takes a while to return and they are executed in order

@smartprogrammer93
Copy link
Contributor Author

@LukaszRozmej not entirely sure which delegate is blocking the invocation. also, parallelizing the the delegate method could lead to its own problems in my opinion (with concurrency and race conditions). Additionally, This solution guarantees that all delegates finish executing before continuing to execute the rest of the code.

@smartprogrammer93
Copy link
Contributor Author

I will not merge this till it is properly tested and be sure it will resolve the issue. @kamilchodola waiting on your confirmation, as i am not sure how exactly you were able to produce it. was not able to do so.

@smartprogrammer93 smartprogrammer93 changed the title [Fix] MultiSyncModeSelector.Changed event propagation being blocked by other event handlers [Fix] MultiSyncModeSelector.Changed event propagation being blocked by some subscribers Jan 13, 2024
@benaadams benaadams added the bug label Jan 14, 2024
@LukaszRozmej
Copy link
Member

@LukaszRozmej not entirely sure which delegate is blocking the invocation. also, parallelizing the the delegate method could lead to its own problems in my opinion (with concurrency and race conditions). Additionally, This solution guarantees that all delegates finish executing before continuing to execute the rest of the code.

Well it makes it explicit and something to handle by the end-user, which actually allows for proper handling of race conditions. Now it is hidden.

Copy link
Contributor

@flcl42 flcl42 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we make so sync starts only when migrations are done?

@LukaszRozmej
Copy link
Member

What was the problem?

Multiple events subscribed to the event; important one is second, first one takes a while to return and they are executed in order

I would execute first one parallel explicitly in the handler, don't you think it is better?

@smartprogrammer93
Copy link
Contributor Author

@LukaszRozmej i disagree. since if another syncmode change happens while the handler is still executing the previous one it could lead to a race condition.
With this approach, the parallel for guarantees the execution of all of the handlers is done before it releases the thread possibly blocking syncmode from switching before all the previous handlers have already finished execution.

@smartprogrammer93 smartprogrammer93 force-pushed the fix/syncmodeselector-changed-event-propegation-blocking branch from 51bb2b7 to ec355fd Compare March 6, 2024 20:15
@smartprogrammer93 smartprogrammer93 changed the title [Fix] MultiSyncModeSelector.Changed event propagation being blocked by some subscribers [Fix] MultiSyncModeSelector.Changed event propagation being blocked by SyncFeed Mar 6, 2024
@smartprogrammer93 smartprogrammer93 added Smoke Tests Needed QA Team needs to run smoke tests on this change before it is merged sync labels Mar 6, 2024
@smartprogrammer93 smartprogrammer93 added fix and removed bug labels Mar 7, 2024
@kamilchodola
Copy link
Contributor

@smartprogrammer93 @LukaszRozmej what about this one?

@smartprogrammer93
Copy link
Contributor Author

Ready from my side. Feel free to merge it if no more testing is needed. @kamilchodola

@LukaszRozmej LukaszRozmej merged commit 0af9d89 into master Aug 24, 2024
67 checks passed
@LukaszRozmej LukaszRozmej deleted the fix/syncmodeselector-changed-event-propegation-blocking branch August 24, 2024 08:29
@rubo rubo mentioned this pull request Aug 24, 2024
10 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
fix Smoke Tests Needed QA Team needs to run smoke tests on this change before it is merged sync
Projects
None yet
6 participants