diff options
author | thedarkone <thedarkone2@gmail.com> | 2015-11-28 01:40:21 +0100 |
---|---|---|
committer | thedarkone <thedarkone2@gmail.com> | 2015-11-28 01:40:21 +0100 |
commit | ab3c4a4083cce34131eeb23df42041fafe063fc3 (patch) | |
tree | 73418a2a78df36fc4ff0ac62202f39be66713ef7 /activesupport/lib | |
parent | 9d7d12c0044751a494162760cd018fb66eab200f (diff) | |
download | rails-ab3c4a4083cce34131eeb23df42041fafe063fc3.tar.gz rails-ab3c4a4083cce34131eeb23df42041fafe063fc3.tar.bz2 rails-ab3c4a4083cce34131eeb23df42041fafe063fc3.zip |
Subscribing to notifications while inside the said instrumented section.
The issue is that on the exit from Instrumenter#instrument section,
an Evented listener will run into an error because its thread local
(Thread.current[:_timestack]) has not been set up by the #start
method (this obviously happens because the Evented listeners didn't
exist at the time, since no subscribtion to that section was made yet).
Note: support for subscribing to instrumented sections, while being
inside those instrumented sections, might be removed in the future.
Maybe fixes #21873.
Diffstat (limited to 'activesupport/lib')
-rw-r--r-- | activesupport/lib/active_support/notifications/fanout.rb | 4 | ||||
-rw-r--r-- | activesupport/lib/active_support/notifications/instrumenter.rb | 9 |
2 files changed, 9 insertions, 4 deletions
diff --git a/activesupport/lib/active_support/notifications/fanout.rb b/activesupport/lib/active_support/notifications/fanout.rb index 7798c7ec60..c53f9c1039 100644 --- a/activesupport/lib/active_support/notifications/fanout.rb +++ b/activesupport/lib/active_support/notifications/fanout.rb @@ -42,8 +42,8 @@ module ActiveSupport listeners_for(name).each { |s| s.start(name, id, payload) } end - def finish(name, id, payload) - listeners_for(name).each { |s| s.finish(name, id, payload) } + def finish(name, id, payload, listeners = listeners_for(name)) + listeners.each { |s| s.finish(name, id, payload) } end def publish(name, *args) diff --git a/activesupport/lib/active_support/notifications/instrumenter.rb b/activesupport/lib/active_support/notifications/instrumenter.rb index 075ddc2382..67f2ee1a7f 100644 --- a/activesupport/lib/active_support/notifications/instrumenter.rb +++ b/activesupport/lib/active_support/notifications/instrumenter.rb @@ -15,14 +15,15 @@ module ActiveSupport # and publish it. Notice that events get sent even if an error occurs # in the passed-in block. def instrument(name, payload={}) - start name, payload + # some of the listeners might have state + listeners_state = start name, payload begin yield payload rescue Exception => e payload[:exception] = [e.class.name, e.message] raise e ensure - finish name, payload + finish_with_state listeners_state, name, payload end end @@ -36,6 +37,10 @@ module ActiveSupport @notifier.finish name, @id, payload end + def finish_with_state(listeners_state, name, payload) + @notifier.finish name, @id, payload, listeners_state + end + private def unique_id |