Skip to content

rootlessnetns: do not pool the unshared thread - #1110

Open
vtushar06 wants to merge 1 commit into
podman-container-tools:mainfrom
vtushar06:fix-rootlessnetns-thread-leak
Open

rootlessnetns: do not pool the unshared thread#1110
vtushar06 wants to merge 1 commit into
podman-container-tools:mainfrom
vtushar06:fix-rootlessnetns-thread-leak

Conversation

@vtushar06

Copy link
Copy Markdown

setupMounts unshares the mount namespace, but ns.Do() saves and restores only the net namespace and then unlocks the thread, so it goes back to the go scheduler still inside that namespace and later goroutines can run there with the wrong /run.

Do() already handles this case for its own failure path, its comment says to leave the thread locked to die. Taking a second lock here means its unlock leaves the count at one, so the runtime scraps the thread when the goroutine ends instead of pooling it.

Checked how often a pooled thread actually gets picked up again, by locking a thread, unsharing CLONE_NEWNS, unlocking, then reading /proc/thread-self/ns/mnt from 2000 goroutines:

1 leaked thread     87 of 2000 goroutines landed on it   4.4%
11 leaked threads   1451 of 2000                         72.5%

I have not tied it to a user visible bug, / is MS_SLAVE so /usr and /etc stay right and only /run is wrong in there.

Fixes: #1109

Signed-off-by: Tushar Verma <tusharmyself06@gmail.com>
@github-actions github-actions Bot added the common Related to "common" package label Aug 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

common Related to "common" package

Projects

None yet

Development

Successfully merging this pull request may close these issues.

rootlessnetns leaks the unshared mount namespace onto a pooled thread

1 participant