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

Fix `thread_mattr_accessor` thread-local variable naming #24143

Merged
merged 1 commit into from Mar 11, 2016

Conversation

Projects
None yet
5 participants
@perceptec
Contributor

perceptec commented Mar 10, 2016

I believe there's an oopsie in the current implentation of thread_mattr_accessor, which is setting differently-named thread variables when defining class and instance writer methods, so the method isn't working as documented:

    Account.user = "DHH"
    Account.user # => "DHH"
    Account.new.user # => nil
    a = Account.new
    a.user = "ABC" # => "ABC"
    a.class.user # => "DHH"

At this point :attr_Account_user and :attr_Class_user thread-local variables have been created. This change modifies the reader and writer methods to use the class name, instead of 'Class'.

A comparison test has been added (we're already testing the setters above), and all AS tests are passing.

Please scrutinize. :)

@rails-bot

This comment has been minimized.

rails-bot commented Mar 10, 2016

Thanks for the pull request, and welcome! The Rails team is excited to review your changes, and you should hear from @rafaelfranca (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.

Please see the contribution instructions for more information.

@perceptec

This comment has been minimized.

Contributor

perceptec commented Mar 10, 2016

"1 failing check" != "All checks have failed" 😄

This was developed on Ruby 2.3.0 and I see the build issue was specifically with 2.2.4 with GEM and FAYE environment variables set. I've set and confirmed these, fired up 2.2.4 (albeit on OS X, not Debian), and the ActionCable test suite as a whole has been passing, minus a deadlock error on one pass, which is concerning, but may not be related to this particular change.

@perceptec

This comment has been minimized.

Contributor

perceptec commented Mar 11, 2016

By using Faye (export FAYE=1) with current master, I can generate a failure with the Action Cable test suite fairly reliably.

The error's always a variant of:

1) Failure: AsyncAdapterTest#test_identical_subscriptions [../rails/actioncable/test/subscription_adapter/common.rb:35]: Failed assertion, no message given.

(A number of tests call subscribe_as_queue, so sometimes it's test_broadcast_after_unsubscribe, test_channel_filtered_broadcast, etc.)

This points to assert subscribed.set?, and I wonder if there isn't a race condition here.

If so, it's a separate issue (and should probably be submitted as such), but I believe that's what the Travis build failure above was about.

To reproduce, try:

rails/actioncable:$ export FAYE=1
rails/actioncable:$ bundle exec rake test

3-5x or so...

@rafaelfranca

View changes

activesupport/lib/active_support/core_ext/module/attribute_accessors_per_thread.rb Outdated
@@ -47,7 +47,7 @@ def self.#{sym}
unless options[:instance_reader] == false || options[:instance_accessor] == false
class_eval(<<-EOS, __FILE__, __LINE__ + 1)
def #{sym}
Thread.current[:"attr_#{self.class.name}_#{sym}"]
Thread.current[:"attr_#{self.name}_#{sym}"]

This comment has been minimized.

@rafaelfranca

rafaelfranca Mar 11, 2016

Member

Only name as the previous definition should work.

@rafaelfranca rafaelfranca added this to the 5.0.0 milestone Mar 11, 2016

Fix `thread_mattr_accessor` thread-local variable naming
The current implentation of `thread_mattr_accessor` is setting
differently-named thread variables when defining class and
instance writer methods, so the method isn't working as documented:

    Account.user = "DHH"
    Account.user # => "DHH"
    Account.new.user # => nil
    a = Account.new
    a.user = "ABC" # => "ABC"
    a.class.user # => "DHH"

At this point `:attr_Account_user` and `:attr_Class_user` thread-local
variables have been created. Modify the reader and writer methods to use
the class name instead of 'Class'.

@perceptec perceptec force-pushed the perceptec:fix-thread-mattr-accessor-refs branch to 4f2c25d Mar 11, 2016

matthewd added a commit that referenced this pull request Mar 11, 2016

Merge pull request #24143 from perceptec/fix-thread-mattr-accessor-refs
Fix `thread_mattr_accessor` thread-local variable naming

@matthewd matthewd merged commit 1205177 into rails:master Mar 11, 2016

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@perceptec perceptec deleted the perceptec:fix-thread-mattr-accessor-refs branch Mar 11, 2016

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment