Skip to content

gh-159130: _remote_debugging: Do not return another thread when the selected thread is filtered out - #159132

Merged
pablogsal merged 7 commits into
python:mainfrom
maurycy:remote-debugging-next-thread
Nov 24, 2026
Merged

pablogsal merged 7 commits into
python:mainfrom
maurycy:remote-debugging-next-thread

Conversation

@maurycy

@maurycy maurycy commented Oct 10, 2026 •

Copy link
Copy Markdown
Contributor

Please see #159130 for more details.

Repro no longer holds:

maurycy@gimel cpython-issue1 (remote-debugging-next-thread b20e3d1*?) % cat /tmp/repro_filter.py
import os, threading, time
from _remote_debugging import RemoteUnwinder

PROFILING_MODE_EXCEPTION = 4


def sample():
    time.sleep(0.2)
    unwinder = RemoteUnwinder(
        os.getpid(), only_active_thread=True, mode=PROFILING_MODE_EXCEPTION
    )
    print("sampler:", threading.get_native_id())
    print(
        "sampled:",
        [
            (t.thread_id, t.frame_info[0].funcname)
            for i in unwinder.get_stack_trace()
            for t in i.threads
        ],
    )


t = threading.Thread(target=sample)
t.start()
try:
    raise ValueError
except ValueError:
    t.join()
maurycy@gimel cpython-issue1 (remote-debugging-next-thread b20e3d1*?) % ./python.exe /tmp/repro_filter.py
sampler: 10865679
sampled: []
maurycy@gimel cpython-issue1 (remote-debugging-next-thread b20e3d1*?) %

@maurycy
maurycy requested a review from pablogsal as a code owner October 10, 2026 16:47
@maurycy maurycy changed the title gh-159130: _remote_debugging: Don't replace a filtered thread with the next one gh-159130: _remote_debugging: Don't replace a filtered out thread with the next one Oct 10, 2026
@maurycy maurycy changed the title gh-159130: _remote_debugging: Don't replace a filtered out thread with the next one gh-159130: _remote_debugging: only_active_thread=True can return a different thread after mode filtering Oct 10, 2026
@maurycy maurycy changed the title gh-159130: _remote_debugging: only_active_thread=True can return a different thread after mode filtering gh-159130: _remote_debugging: Do not return another thread when the selected thread is filtered out Oct 10, 2026
goto exit;
}
// Thread was skipped due to mode filtering, continue to next thread
if (self->tstate_addr || self->only_active_thread) {

@maurycy maurycy Oct 10, 2026 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if (self->tstate_addr || self->only_active_thread) {
if (self->only_active_thread) {

I think this could be sufficient but I kept this the same as this condition for symmetry:

https://github.com/python/cpython/pull/159132/changes#diff-9676fd8cee6e0d841f42f405a8e33a434fbebbc861207051571c97cef17c4108R848-R850

@pablogsal pablogsal added the needs backport to 3.15 bugs and security fixes label Nov 24, 2026

@pablogsal pablogsal left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM! Thanks for the fix, Maurycy!

@pablogsal
pablogsal enabled auto-merge (squash) November 24, 2026 12:33
@maurycy

maurycy commented Nov 24, 2026

Copy link
Copy Markdown
Contributor Author

@pablogsal Thank you for the merge:) Always a pleasure!

@pablogsal
pablogsal merged commit 28081fe into python:main Nov 24, 2026
65 checks passed
@miss-islington-app

Copy link
Copy Markdown

Thanks @maurycy for the PR, and @pablogsal for merging it 🌮🎉.. I'm working now to backport this PR to: 3.15.
🐍🍒⛏🤖

@bedevere-app

bedevere-app Bot commented Nov 24, 2026

Copy link
Copy Markdown

GH-162549 is a backport of this pull request to the 3.15 branch.

@bedevere-app bedevere-app Bot removed the needs backport to 3.15 bugs and security fixes label Nov 24, 2026
@maurycy
maurycy deleted the remote-debugging-next-thread branch November 24, 2026 13:06
pablogsal pushed a commit that referenced this pull request Nov 24, 2026
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