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

[FIXED] Possible lock inversion and incorrect delete of JS consumer #792

Closed
wants to merge 2 commits into from

Conversation

kozlovic
Copy link
Member

  • Some refactoring to prevent lock inversion (no connection publish
    should be done under the subscription lock).
  • Remove used of jsSub mutex since so far everything can be done
    under the protection of the subscription's lock.
  • Attempt to delete JS consumer on Unsubscribe only if the library
    called AddConsumer and got a success.

Resolves #775
Resolves #776

Signed-off-by: Ivan Kozlovic ivan@synadia.com

- Some refactoring to prevent lock inversion (no connection publish
should be done under the subscription lock).
- Remove used of jsSub mutex since so far everything can be done
under the protection of the subscription's lock.
- Attempt to delete JS consumer on Unsubscribe *only* if the library
called AddConsumer and got a success.

Resolves #775
Resolves #776

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
Copy link
Member

@derekcollison derekcollison left a comment

Choose a reason for hiding this comment

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

In general looks good. Not a fan of delCons vs attached and I think we need to think harder on when a sub.Unsubscribe() is supposed to delete an underlying JetStream consumer.

js.go Show resolved Hide resolved
js.go Outdated Show resolved Hide resolved
js.go Outdated Show resolved Hide resolved
js.go Outdated Show resolved Hide resolved
@coveralls
Copy link

coveralls commented Aug 10, 2021

Coverage Status

Coverage increased (+0.3%) to 87.205% when pulling edbc1cd on fix_775_776 into d1955c8 on master.

If set, the JS consumer will be deleted:
- On Unsubscribe(), if error occurs, error is returned.
- After Drain (connection and/or subscription) completes. If error
occurs there, error is reported through async error cb.

Signed-off-by: Ivan Kozlovic <ivan@synadia.com>
js.go Show resolved Hide resolved
t.Run("durable consumers not deleted on drain", func(t *testing.T) {
subB, err := js.SubscribeSync("foo.B", nats.Durable("B"))
t.Run("durable consumers deleted on drain", func(t *testing.T) {
subB, err := js.Subscribe("foo.B", func(_ *nats.Msg) {}, nats.Durable("B"), nats.DeleteConsumer())
Copy link
Member

@derekcollison derekcollison Aug 11, 2021

Choose a reason for hiding this comment

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

All these changes still needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Meaning? These tests are about checking that consumers are deleted, but the semantic have changed a bit. I could refactor them completely to match the current expectations as opposed to try "fixing" them. Will do that tomorrow.

Copy link
Member

Choose a reason for hiding this comment

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

Sounds good. Looking at the examples, would you add the opt to Unsubscribe() vs Subscribe()?

Copy link
Member Author

@kozlovic kozlovic Aug 11, 2021

Choose a reason for hiding this comment

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

Although it would make more sense, I would not change Unsubscribe()/Drain() (even adding var option may cause backward compatibility issues, and may not be possible in other lang).

@kozlovic
Copy link
Member Author

Closing this PR and will open a new one that is more comprehensive.

@kozlovic kozlovic closed this Aug 14, 2021
@kozlovic kozlovic deleted the fix_775_776 branch August 14, 2021 21:56
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.

JS: Library possibly removes a consumer when it should not JS: Possible lock inversion
3 participants