Skip to content

fix: give back the thread ports a CPU sample is handed - #25

Merged
heoblitz merged 2 commits into
toss:mainfrom
wjdtjq6:fix/process-metrics-thread-ports
Oct 15, 2026
Merged

heoblitz merged 2 commits into
toss:mainfrom
wjdtjq6:fix/process-metrics-thread-ports

Conversation

@wjdtjq6

@wjdtjq6 wjdtjq6 commented Oct 13, 2026

Copy link
Copy Markdown

Summary

task_threads returns a send right for every thread along with the list, and the CPU sampler in NectoProcessMetrics released only the list (vm_deallocate). Each port it kept outlives its thread as a dead name, so while the Performance panel is observing — one sample a second — the app it runs in accumulates one Mach port name for every thread it ever ran. Each port is now mach_port_deallocated before the list is freed.

Changelog

Fix the Performance plugin leaking a Mach port per sampled thread in the connected app.

Test Plan

  • swift test: 161 tests in 11 suites passed. The new test releasesThreadPorts parks a short-lived thread, takes a performance.snapshot, ends the thread, 300 times over, and compares mach_port_names counts: on main it leaks 301 names; with the fix the delta stays under the 100 allowed for noise.

task_threads returns a port for every thread along with the list, and
only the list was released. Each port kept outlived its thread as a
dead name, so an observed Performance panel, sampling once a second,
left one behind in the app for every thread it ever ran.
@heoblitz
heoblitz merged commit a1a96a8 into toss:main Oct 15, 2026
5 checks passed
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.

2 participants