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

Add contexts to pubsub.Subscribe to allow early cancelation #1756

Merged
merged 1 commit into from
Jun 2, 2022

Conversation

ItalyPaleAle
Copy link
Contributor

@ItalyPaleAle ItalyPaleAle commented May 25, 2022

Description

This PR is related to dapr/dapr#4624. As noted there, we have an issue in the runtime where all components are shut down after the grace period, when the app is likely already stopped. Because of that, certain input components (the subscribe part of pubsub and the input part of bindings - the latter not in scope of this PR), can continue bringing new work when it's known to fail.

In order to fix the issue linked above properly, we need to implement a way for PubSub components to have the "publish" part closed before the "subscribe" one (and in the future that will need to be done for input bindings too).

This PR achieves precisely that by adding a context in the Subscribe method. When that context is canceled (which can be at any time), the subscription is removed.

PS: This API change was implemented so it can one day be used for dapr/dapr#814 too, as it allows canceling individual subscriptions by using a different context. Although that's not possible today because it requires more work on the runtime, it does implement everything that's needed in the pubsub components already.

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests

TODO

Marking this PR as draft until the following are done (in order):

  1. Update conformance tests to test the new behavior
  2. Merge Fixes for SNS/SQS PubSub #1754 (included in this PR)
  3. Merge Fixed Kafka PubSub to allow multiple handlers for different topics #1755 (included in this PR)
  4. Merge Add additional Event Hub topics for certification tests #1767 (not merged, but implemented)
  5. Merge Added test for multiple pubsub handlers #1743 (included in this PR)

@ItalyPaleAle
Copy link
Contributor Author

/ok-to-test

@ItalyPaleAle
Copy link
Contributor Author

/ok-to-test

ItalyPaleAle added a commit to ItalyPaleAle/dapr that referenced this pull request Jun 2, 2022
With dapr/components-contrib#1756, it's now possible to stop receiving messages from pubsub components via context cancelation. This makes it so we won't receive more work while the sidecar is shutting down, but we can still publish messages in pubsub.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
This commit is related to dapr/dapr#4624. As noted there, we have an issue in the runtime where all components are shut down after the grace period, when the app is likely already stopped. Because of that, certain input components (the subscribe part of pubsub and the input part of bindings - the latter not in scope of this PR), can continue bringing new work when it's known to fail.

In order to fix the issue linked above properly, we need to implement a way for PubSub components to have the "publish" part closed before the "subscribe" one (and in the future that will need to be done for input bindings too).

This commit achieves precisely that by adding a context in the Subscribe method. When that context is canceled (which can be at any time), the subscription is removed.

PS: This API change was implemented so it can one day be used for dapr/dapr#814 too, as it allows canceling individual subscriptions by using a different context. Although that's not possible today because it requires more work on the runtime, it does implement everything that's needed in the pubsub components already.
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@@ -163,6 +162,7 @@ require (
github.com/huaweicloud/huaweicloud-sdk-go-v3 v0.0.87
github.com/labd/commercetools-go-sdk v0.3.2
github.com/nacos-group/nacos-sdk-go/v2 v2.0.1
github.com/rabbitmq/amqp091-go v1.3.4
Copy link
Contributor Author

Choose a reason for hiding this comment

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

github.com/rabbitmq/amqp091-go is the new version of github.com/streadway/amqp and it's maintained by RabbitMQ now

@codecov
Copy link

codecov bot commented Jun 2, 2022

Codecov Report

Merging #1756 (c9f5c32) into master (e2aced1) will decrease coverage by 0.07%.
The diff coverage is 20.52%.

@@            Coverage Diff             @@
##           master    #1756      +/-   ##
==========================================
- Coverage   36.74%   36.67%   -0.08%     
==========================================
  Files         176      177       +1     
  Lines       15955    16200     +245     
==========================================
+ Hits         5863     5941      +78     
- Misses       9434     9590     +156     
- Partials      658      669      +11     
Impacted Files Coverage Δ
bindings/alicloud/dingtalk/webhook/webhook.go 52.68% <ø> (ø)
bindings/alicloud/nacos/nacos.go 35.60% <ø> (ø)
bindings/alicloud/rocketmq/rocketmq.go 0.00% <ø> (ø)
bindings/aws/kinesis/kinesis.go 2.61% <ø> (ø)
bindings/aws/sqs/sqs.go 6.55% <ø> (ø)
bindings/azure/eventgrid/eventgrid.go 3.84% <ø> (ø)
bindings/azure/eventhubs/eventhubs.go 14.79% <ø> (ø)
...indings/azure/servicebusqueues/servicebusqueues.go 10.69% <ø> (ø)
bindings/azure/storagequeues/storagequeues.go 33.87% <ø> (ø)
bindings/cron/cron.go 87.23% <ø> (ø)
... and 34 more

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 7c35a4e...c9f5c32. Read the comment docs.

@ItalyPaleAle
Copy link
Contributor Author

Note that all certification tests will fail until the corresponding PR is merged in dapr/dapr, due to a change in the interface of the pubsub components

@yaron2 yaron2 merged commit 704f4dd into dapr:master Jun 2, 2022
ItalyPaleAle added a commit to ItalyPaleAle/dapr that referenced this pull request Jun 3, 2022
With dapr/components-contrib#1756, it's now possible to stop receiving messages from pubsub components via context cancelation. This makes it so we won't receive more work while the sidecar is shutting down, but we can still publish messages in pubsub.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
artursouza pushed a commit to dapr/dapr that referenced this pull request Jun 3, 2022
* Updated pinned components-contrib

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>

* Stop pubsub subscriptions before shutdown grace period

With dapr/components-contrib#1756, it's now possible to stop receiving messages from pubsub components via context cancelation. This makes it so we won't receive more work while the sidecar is shutting down, but we can still publish messages in pubsub.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
beiwei30 pushed a commit to beiwei30/components-contrib that referenced this pull request Jun 7, 2022
This commit is related to dapr/dapr#4624. As noted there, we have an issue in the runtime where all components are shut down after the grace period, when the app is likely already stopped. Because of that, certain input components (the subscribe part of pubsub and the input part of bindings - the latter not in scope of this PR), can continue bringing new work when it's known to fail.

In order to fix the issue linked above properly, we need to implement a way for PubSub components to have the "publish" part closed before the "subscribe" one (and in the future that will need to be done for input bindings too).

This commit achieves precisely that by adding a context in the Subscribe method. When that context is canceled (which can be at any time), the subscription is removed.

PS: This API change was implemented so it can one day be used for dapr/dapr#814 too, as it allows canceling individual subscriptions by using a different context. Although that's not possible today because it requires more work on the runtime, it does implement everything that's needed in the pubsub components already.
Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
ItalyPaleAle added a commit to ItalyPaleAle/dapr that referenced this pull request Jun 8, 2022
* Updated pinned components-contrib

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>

* Stop pubsub subscriptions before shutdown grace period

With dapr/components-contrib#1756, it's now possible to stop receiving messages from pubsub components via context cancelation. This makes it so we won't receive more work while the sidecar is shutting down, but we can still publish messages in pubsub.

Signed-off-by: ItalyPaleAle <43508+ItalyPaleAle@users.noreply.github.com>
@berndverst berndverst added this to the v1.8 milestone Jun 21, 2022
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.

None yet

3 participants