Skip to content

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

Merged
tenderlove merged 1 commit into
rails:masterfrom
zvkemp:asn-unsubscribe-proxy
Feb 12, 2019
Merged

use ProxyPattern to match for ActiveSupport::Notifications fanout/unsubscribe#32861
tenderlove merged 1 commit into
rails:masterfrom
zvkemp:asn-unsubscribe-proxy

Conversation

@zvkemp

@zvkemp zvkemp commented May 9, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown

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.

@dillonwelch

Copy link
Copy Markdown
Contributor

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 commented Sep 29, 2018

Copy link
Copy Markdown
Contributor Author

@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 Compare February 7, 2019 22:26
@tenderlove

Copy link
Copy Markdown
Member

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

@jhawthorn jhawthorn Feb 11, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

How about @unsubscribed?

@jhawthorn jhawthorn left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Other than two comments this looks good to me.

@zvkemp
zvkemp force-pushed the asn-unsubscribe-proxy branch from fee6548 to 94f8e8c Compare February 12, 2019 00:04
@zvkemp

zvkemp commented Feb 12, 2019

Copy link
Copy Markdown
Contributor Author

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

@tenderlove

Copy link
Copy Markdown
Member

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

Great! Thank you!

@tenderlove

Copy link
Copy Markdown
Member

I'll merge this once CI returns. πŸ˜„

@tenderlove
tenderlove merged commit 87a5b5d into rails:master Feb 12, 2019
@zvkemp
zvkemp deleted the asn-unsubscribe-proxy branch February 13, 2019 16:54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants