diff --git a/lib/app_profiler/server.rb b/lib/app_profiler/server.rb index 147dc59..a2e9a93 100644 --- a/lib/app_profiler/server.rb +++ b/lib/app_profiler/server.rb @@ -158,7 +158,12 @@ def start_running(stackprof_args) @profile_running = true - AppProfiler.start(**stackprof_args) + AppProfiler.start(**stackprof_args).tap do |started| + @profile_running = false unless started + end + rescue + @profile_running = false + raise end end diff --git a/test/app_profiler/profile_server_test.rb b/test/app_profiler/profile_server_test.rb index c59cdb4..d0e4a80 100644 --- a/test/app_profiler/profile_server_test.rb +++ b/test/app_profiler/profile_server_test.rb @@ -353,6 +353,19 @@ def app AppProfiler.stop end + test "app can start profiling again after external conflict clears" do + begin + AppProfiler.start + get("/profile?duration=0.01") + assert_equal(decode_status(last_response.status), Net::HTTPConflict) + ensure + AppProfiler.stop + end + + get("/profile?duration=0.01") + assert(last_response.ok?) + end + private def with_profiled_workload(workload, &block)