Skip to content

fix(profiling): Release the Excimer profiler when the transaction profiler stops - #2424

Open
stayallive wants to merge 1 commit into
masterfrom
fix/release-excimer-profiler-on-stop
Open

stayallive wants to merge 1 commit into
masterfrom
fix/release-excimer-profiler-on-stop

Conversation

@stayallive

Copy link
Copy Markdown
Collaborator

Description

Finished profiled transactions kept their Excimer timer (a thread on Linux) alive until PHP's cycle collector ran. A Transaction is part of a reference cycle (its span recorder contains the transaction itself, and child spans reference it), so unsetting it doesn't free it. It held on to the Profiler, which held the \ExcimerProfiler, whose OS timer is only released on destruction, not on stop(). In long-running workers the collector may not run often enough, and the process can hit its thread limit (ExcimerProfiler::start(): Error in pthread_create(): Resource temporarily unavailable).

Profiler::stop() now drops the \ExcimerProfiler right after flushing its log. getProfile() uses a separate availability flag, so it still returns the collected profile after stop(). Profiler is final and @internal, and Transaction::getProfiler() behaves as before.

Reproduced with the script from the issue (Linux, PHP 8.4, ext-excimer 1.2.6):

before: after50=51 after_gc=1
after:  after50=1  after_gc=1

Added tests/Profiling/ProfilerTest.php (requires excimer), which checks that stop() releases the Excimer profiler while the profile stays available, and that a finished transaction still attaches its profile to the event. Both tests fail without the fix.

Issues

🤖 Generated with Claude Code

…filer stops

A finished transaction is part of a reference cycle (span recorder and child
spans), so it is only freed by PHP's cycle collector. It kept the Profiler and
therefore the ExcimerProfiler alive, whose OS timer (a thread on Linux) is only
freed on destruction. Long-running workers could exhaust their thread limit.

Profiler::stop() now drops the ExcimerProfiler after flushing its log, while
getProfile() keeps returning the collected profile.

Fixes #2423

Co-Authored-By: Claude <noreply@anthropic.com>
@stayallive
stayallive requested a review from a team as a code owner November 24, 2026 10:56
@linear-code

linear-code Bot commented Nov 24, 2026

Copy link
Copy Markdown

PHP-109

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Finished profiled transactions keep their Excimer thread until a GC cycle runs

1 participant