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

🚧Prevent unsubscription in OnRecieve #181

Closed
10 tasks done
CalvinWilkinson opened this issue Jan 7, 2024 · 0 comments · Fixed by #194
Closed
10 tasks done

🚧Prevent unsubscription in OnRecieve #181

CalvinWilkinson opened this issue Jan 7, 2024 · 0 comments · Fixed by #194
Assignees
Labels
✨new-feature New feature that does not exist tech-debt Code refactoring or cleanup / tech debt reduction

Comments

@CalvinWilkinson
Copy link
Member

CalvinWilkinson commented Jan 7, 2024

Complete The Item Below

  • I have updated the title without removing the 🚧 emoji.

Description

Prevent an unsubscriber object from unusubscribing when its Dispose() method is called in an OnReceieve() call.

This can be prevented by invoking an exception. This is because if a user unsubscribes inside of an OnReceieve() method call, this can cause issues due to processing each subscription at a time in the reactables.

To prevent this from being an issue, the for loops in the reactables all iterate the list of subscriptions from the end of the loop to the beginning so it does not try to access a subscription item that does not exist.

Why is this?
When a SubscriptionUnsubscriber.Dispose()' method is called, it directly removes the subscription from the reactable's underlying array. The OnReceieve()` methods are invoked in an array. This can cause a state of accessing an item that has been removed.

If we throw an exception from the unsubscriber, this will prevent users from trying to call the Dispose() method in the OnReceieve() call stack.

How to prevent this?
Internally, have the reactable communicate a state that the reactable is in the middle of processing notifications. If this is the case, the Dispose() method of the unsubscriber should throw an exception.

  1. Add a new parameter with the type Func<bool> and the name isProcessing to the SubscriptionUnsubscriber constructor. The bool value will be the processing state that the reactable is currently in. A value of true will mean that notifications are being processed and false means it is not.

Note

The ReactableBase class will have a private method that returns a bool value that will be passed as the new ctor
parameter of the `SubscriptionUnsubsciber' class. The unsubscriber will then invoke this to check the processing
state of the reactable that the subscription belongs to.

  1. In the methods Push and SendError methods of the PushReactable<TIn> and NonDirectional.PushReactable classes, set the state to processing before the loops start and to not processing after the loops end.
  2. Do the same thing for the PushPullReactable<TIn, TOut>.PushPull method.

Before the loop starts in the reactables, set the value of this property for each subscription

Acceptance Criteria

The items to complete in order to satisfy the Definition of Done.

ToDo Items

The items to complete in order to satisfy the Definition of Done.

Issue Dependencies

No response

Related Work

No response

Additional Information:

Change Type Labels

Change Type Label
Bug Fixes 🐛bug
Breaking Changes 🧨breaking changes
New Feature ✨new feature
CICD Changes ♻️cicd
Config Changes ⚙️config
Performance Improvements 🏎️performance
Code Doc Changes 🗒️documentation/code
Product Doc Changes 📝documentation/product

Priority Type Labels

Priority Type Label
Low Priority low priority
Medium Priority medium priority
High Priority high priority

Code of Conduct

  • I agree to follow this project's Code of Conduct.
@CalvinWilkinson CalvinWilkinson self-assigned this Jan 7, 2024
@CalvinWilkinson CalvinWilkinson added tech-debt Code refactoring or cleanup / tech debt reduction ✨new-feature New feature that does not exist labels Jan 7, 2024
@CalvinWilkinson CalvinWilkinson added this to the v1.0.0-preview.17 milestone Jan 22, 2024
CalvinWilkinson added a commit that referenced this issue Jan 22, 2024
CalvinWilkinson added a commit that referenced this issue Jan 23, 2024
* Start work for issue #181

* chore: improve subscription unsubscriber implementation

* feat: create new exception for handling notification processing errors

* feat: add param to ctor to take a delegate to get the processing state

* feat: setup non-dir reactable to throw exception is unsubscribing during processing

* feat: setup one-way push reactable to throw exception is unsubscribing during processing

* feat: setup one-way pull reactable to throw exception is unsubscribing during processing

* feat: setup two-way push pull reactable to throw exception is unsubscribing during processing

* docs: improve readme
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
✨new-feature New feature that does not exist tech-debt Code refactoring or cleanup / tech debt reduction
Projects
Archived in project
Development

Successfully merging a pull request may close this issue.

1 participant