Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions lib/mini_profiler.rb
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ def tool_disabled_message(client_settings)

def call(env)
start = Process.clock_gettime(Process::CLOCK_MONOTONIC)
outer_context = current
client_settings = ClientSettings.new(env, @storage, start)
MiniProfiler.deauthorize_request if @config.authorization_mode == :allow_authorized

Expand Down Expand Up @@ -415,8 +416,8 @@ def call(env)

client_settings.handle_cookie([status, headers, body])
ensure
# Make sure this always happens
self.current = nil
# Make sure this always happens, restoring the context of an outer request on the same thread
self.current = outer_context
end

def matches_action?(action, env)
Expand Down
14 changes: 14 additions & 0 deletions spec/integration/mini_profiler_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -717,4 +717,18 @@ def load_prof(response)
expect(last_response.body).to include('This is the help menu')
end
end

describe 'with a nested request on the same thread' do
it 'keeps the outer request profiled' do
inner = Rack::MiniProfiler.new(lambda { |env| [200, { Rack::CONTENT_TYPE => 'text/html' }, +'<h1>inner</h1>'] })
outer = Rack::MiniProfiler.new(lambda { |env|
Rack::MockRequest.new(inner).get('/inner')
[200, { Rack::CONTENT_TYPE => 'text/html' }, +'<html><body><h1>outer</h1></body></html>']
})

response = Rack::MockRequest.new(outer).get('/outer')
expect(response.status).to eq(200)
expect(response.body).to include('mini-profiler')
end
end
end