From 6dd111938ae48646f19219703f6a63a0090c4d7c Mon Sep 17 00:00:00 2001 From: Andrii Furmanets Date: Wed, 18 Feb 2026 20:58:14 +0200 Subject: [PATCH] Fix profile server running flag after start conflicts --- lib/app_profiler/server.rb | 7 ++++++- test/app_profiler/profile_server_test.rb | 13 +++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) diff --git a/lib/app_profiler/server.rb b/lib/app_profiler/server.rb index 147dc592..a2e9a934 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 c59cdb46..d0e4a809 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)