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

[bug]: ResourceWatcher stops working after leadership changes #522

Closed
tomasfabian opened this issue Feb 3, 2023 · 5 comments
Closed

[bug]: ResourceWatcher stops working after leadership changes #522

tomasfabian opened this issue Feb 3, 2023 · 5 comments
Labels
bug Something isn't working

Comments

@tomasfabian
Copy link
Contributor

tomasfabian commented Feb 3, 2023

Describe the bug

When the leadership changes the ResourceWatcher throws an unobserved exception:

System.AggregateException: A Task's exception(s) were not observed either by Waiting on the Task or accessing its Exception property. As a result, the unobserved exception was rethrown by the finalizer thread. (Cannot access a disposed object.)
 ---> System.ObjectDisposedException: Cannot access a disposed object.
   at System.Reactive.Subjects.Subject`1.ThrowDisposed() in /_/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs:line 53
   at System.Reactive.Subjects.Subject`1.OnNext(T value) in /_/Rx.NET/Source/src/System.Reactive/Subjects/Subject.cs:line 141
   at KubeOps.Operator.Kubernetes.ResourceWatcher`1.OnException(Exception e)
   at k8s.Watcher`1.WatcherLoop(CancellationToken cancellationToken)
   at k8s.Watcher`1.<.ctor>b__9_0()

My suspicion is that this happens after calling the StartAsync again on the same instance after StopAsync.

The problem could be fixed by removing this line where the _reconnectHandler is disposed again outside of the previous if (!fromStop) clause.

To reproduce

Change the leadership from LeaderState.Leader to LeaderState.Candidate and back to LeaderState.Leader.

Expected behavior

The resource watcher should not stop watching after leadership changed.

Screenshots

No response

Additional Context

I can prepare a PR if you will confirm that the issue is legitimate. Could be related to #482.

@tomasfabian tomasfabian added the bug Something isn't working label Feb 3, 2023
@tomasfabian
Copy link
Contributor Author

tomasfabian commented Feb 4, 2023

Shouldn't be the _reconnectSubscription.Dispose(); also inside the if (!fromStop) ? Or the subscription in the ctor should be recreated, because on the next StartAsync call it is not subscribed anymore. Do I understand it correctly, please?

The reconnect subscription should be either recreated on each StartAsync or not disposed during CloseAsync.

@buehler
Copy link
Owner

buehler commented Feb 6, 2023

Hey @tomasfabian
Sorry for the late reply, let me check :-)

@buehler buehler closed this as completed in 79646b3 Feb 6, 2023
@tomasfabian
Copy link
Contributor Author

Hi @buehler,
would it be also possible to release the fix for version 6, please?

Thanks.

@buehler
Copy link
Owner

buehler commented Feb 6, 2023

Hey @tomasfabian
Hmm.... are you not able to upgrade to 7?
backporting is kind of a burden and I need more time to set up release/support branches for semantic release

@tomasfabian
Copy link
Contributor Author

Ok no problem if it is a hassle, we will upgrade our operator to v7.

buehler added a commit that referenced this issue Feb 14, 2023
#482 #522 #523 #526

---------

Co-authored-by: Christoph Bühler <buehler@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants