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

use ProxyPattern to match for ActiveSupport::Notifications fanout/unsubscribe #32861

Merged
merged 1 commit into from Feb 12, 2019

Conversation

@zvkemp
Copy link
Contributor

@zvkemp zvkemp commented May 9, 2018

Summary

Before this change, ActiveSupport::Notifications.unsubscribe would eagerly remove all subscribers for which subscriber.matches?(string) was true, which can cause some unintended behavior in the case of regexes or other compound matchers (in our case, we had a single listener subscribed to a few dozen event keys via a single pattern object that internally checked for inclusion within a set).

Unsubscribing to a single string should not negate any other potential matches for those subscriptions. After this change:

  • [no change] unsubscribing via string for string-based subscriptions will reject the subscription from the array
  • [no change] unsubscribing via subscriber reference removes that subscriber
  • unsubscribing via string for subscriptions with the potential to match multiple values will append that string to a blacklist. This will in turn prevent that pattern from matching that string in the future, so the listener won't be added under that key to the listeners_for map.
@rails-bot
Copy link

@rails-bot rails-bot commented May 9, 2018

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @schneems (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

This repository is being automatically checked for code quality issues using Code Climate. You can see results for this analysis in the PR status below. Newly introduced issues should be fixed before a Pull Request is considered ready to review.

Please see the contribution instructions for more information.

@oniofchaos
Copy link
Contributor

@oniofchaos oniofchaos commented Sep 29, 2018

Looks like there might have been some CodeClimate concerns but the analysis is out of date - can you merge in latest master so we can get an up to date build?

@zvkemp zvkemp force-pushed the asn-unsubscribe-proxy branch from 388cb66 to 2c01532 Sep 29, 2018
@zvkemp
Copy link
Contributor Author

@zvkemp zvkemp commented Sep 29, 2018

@oniofchaos I think there was an issue in master when the previous build ran. I rebased on latest master; everything looks green now!

@zvkemp zvkemp force-pushed the asn-unsubscribe-proxy branch 3 times, most recently from b502722 to fee6548 Feb 7, 2019
@tenderlove
Copy link
Member

@tenderlove tenderlove commented Feb 11, 2019

@jhawthorn you've looked at this code recently. Any opinions?

end

def ===(name)
pattern === name && blacklist.none? { |p| p === name }
Copy link
Member

@jhawthorn jhawthorn Feb 11, 2019

Can we use Set#include? instead? Since we know name and everything in the set to be a string

@@ -39,8 +40,10 @@ def unsubscribe(subscriber_or_name)
when String
@string_subscribers[subscriber_or_name].clear
@listeners_for.delete(subscriber_or_name)
@other_subscribers.each { |sub| sub.blacklist!(subscriber_or_name) }
Copy link
Member

@tenderlove tenderlove Feb 11, 2019

Can you change blacklist! to "restricted_list" or maybe restrict!.

Copy link
Member

@jhawthorn jhawthorn Feb 11, 2019

How about @unsubscribed?

Copy link
Member

@jhawthorn jhawthorn left a comment

Other than two comments this looks good to me.

@zvkemp zvkemp force-pushed the asn-unsubscribe-proxy branch from fee6548 to 94f8e8c Feb 12, 2019
@zvkemp
Copy link
Contributor Author

@zvkemp zvkemp commented Feb 12, 2019

Thanks @jhawthorn and @tenderlove. I've implemented your suggested changes.

@tenderlove
Copy link
Member

@tenderlove tenderlove commented Feb 12, 2019

Thanks @jhawthorn and @tenderlove. I've implemented your suggested changes.

Great! Thank you!

@tenderlove
Copy link
Member

@tenderlove tenderlove commented Feb 12, 2019

I'll merge this once CI returns. 😄

@tenderlove tenderlove merged commit 87a5b5d into rails:master Feb 12, 2019
2 checks passed
@zvkemp zvkemp deleted the asn-unsubscribe-proxy branch Feb 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

7 participants