Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Timing was broken for async endpoints, fix it...

There's only one Rack::Informant instance per app (not per request!), so
for async endpoints, @start would get overwritten by each subsequent
request.  An outstanding request would therefore appear to have started
whenever the most recent request came in, rather than when it actually
started, and thus be reported as quicker than it was.

Fix by using a local variable in #call (which *is* per-request) rather
than an instance variable.

Thanks @ept for pointing this out.
  • Loading branch information...
commit 961d24255146136317c3501e2681dda09a0a5648 1 parent e0978c6
@samstokes samstokes authored
Showing with 5 additions and 5 deletions.
  1. +5 −5 lib/rack/informant.rb
View
10 lib/rack/informant.rb
@@ -30,13 +30,13 @@ def initialize(app, &block)
end
def call(env)
- @start = Time.now
+ start = Time.now
if original_callback = env['async.callback']
env['async.callback'] = proc do |response|
status, headers, body = response
- inform!(env, status, headers, body)
+ inform!(env, start, status, headers, body)
original_callback.call(response)
end
@@ -49,7 +49,7 @@ def call(env)
return [status, headers, body] if status == -1 # alternative async API
# if we got *this* far, @app.call is definitely synchronous
- inform!(env, status, headers, body)
+ inform!(env, start, status, headers, body)
return [status, headers, body]
end
@@ -59,8 +59,8 @@ def call(env)
end
private
- def inform!(env, status, headers, body)
- runtime = Time.now - @start
+ def inform!(env, start, status, headers, body)
+ runtime = Time.now - start
event = {
method: env['REQUEST_METHOD'],
Please sign in to comment.
Something went wrong with that request. Please try again.