Skip to content

Ignore EPERM locking error if thread does not exist - #111

Merged
benfred merged 3 commits into
benfred:masterfrom
I-Al-Istannen:fix/ignore-eperm-exiting-state
Apr 21, 2026
Merged

Ignore EPERM locking error if thread does not exist#111
benfred merged 3 commits into
benfred:masterfrom
I-Al-Istannen:fix/ignore-eperm-exiting-state

Conversation

@I-Al-Istannen

Copy link
Copy Markdown
Contributor

When the thread state is exiting, the Linux kernel's ptrace implementation returns EPERM. If this happens we should skip the exiting thread, instead of stopping sampling altogether.

This reduces the EPERM errors in the threading stress test benfred/py-spy#771 (comment) to zero. Over a 24h run in a larger program it still fails sampling with EPERM sometimes, but this seems to be quite an improvement.

I do not think we can read the exact kernel condition, so this is now open to a race condition: Maybe we really do not have any permission but the thread dies in the split second between the ptrace error and the exists call. In that case we continue sampling, even though we could have died with a permission error instead. I do not think this is a big problem. If we really have no permission, it will crash in the next iteration once it tries to sample a living thread again.

WDYT?

I-Al-Istannen and others added 2 commits July 31, 2025 13:38
When the thread state is exiting, the Linux kernel's ptrace
implementation returns EPERM. If this happens we should skip the exiting
thread, instead of stopping sampling altogether.
@I-Al-Istannen

Copy link
Copy Markdown
Contributor Author

Anything I can do to help you here? :)

Otherwise I also have one or two more fixups in my fork https://github.com/I-Al-Istannen/remoteprocess/commits/master/. I will see which are still relevant and make follow up PRs after this one is merged (or before, if you prefer that) :)

@benfred

benfred commented Apr 21, 2026

Copy link
Copy Markdown
Owner

thanks for the fix!

@benfred benfred added the bug Something isn't working label Apr 21, 2026
@benfred
benfred merged commit 187213b into benfred:master Apr 21, 2026
10 checks passed
@I-Al-Istannen
I-Al-Istannen deleted the fix/ignore-eperm-exiting-state branch April 22, 2026 14:15
@I-Al-Istannen

Copy link
Copy Markdown
Contributor Author

Thanks!

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

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants