Skip to content

gh-153364: Add frame limit in get_async_stack_trace() and parse_coro_chain()#153365

Open
maurycy wants to merge 8 commits into
python:mainfrom
maurycy:tachyon-parse_async_frame_chain-limit
Open

gh-153364: Add frame limit in get_async_stack_trace() and parse_coro_chain()#153365
maurycy wants to merge 8 commits into
python:mainfrom
maurycy:tachyon-parse_async_frame_chain-limit

Conversation

@maurycy

@maurycy maurycy commented Jul 8, 2026

Copy link
Copy Markdown
Contributor

Fixes #153364

The PR hardens and cleans up max frame chain limits a bit.

It introduces a const (MAX_FRAME_CHAIN_DEPTH), uses it in the existing process_frame_chain(), which is called by get_stack_trace(), as well as adds it to parse_coro_chain(), used in both sync and async pathways, and to parse_async_frame_chain().

The obvious context here is avoiding infinite loops. Truth be told, I think that in some places it unexpectedly works (ie: doesn't hang) because incomplete / torn-reads result in an exception. :-)

@@ -325,10 +327,19 @@ int
parse_coro_chain(

@maurycy maurycy Jul 8, 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.

Does it actually need to be recursive?

To put aside recursive v. iterative; CS101 strikes: if you ask me, I was thinking about a visited set here... not applicable to this fix but cycle detected would be such a nice touch. :-)

@maurycy maurycy Jul 9, 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.

I realized we used Floyd's algo at least once:

PyObject *slow_o = o; /* Floyd's cycle detection algo */

I, for one, like Brent's :-)

#define MAX_STACK_CHUNK_SIZE (16 * 1024 * 1024) /* 16 MB max for stack chunks */
#define MAX_LONG_DIGITS 64 /* Allows values up to ~2^1920 */
#define MAX_SET_TABLE_SIZE (1 << 20) /* 1 million entries max for set iteration */
#define MAX_FRAME_CHAIN_DEPTH (1024 + 512) /* Iteration bound for frame chain walks */

@maurycy maurycy Jul 8, 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.

Not the scope but maybe MAX_THREADS, MAX_STACK_CHUNKS, MAX_LINETABLE_ENTRIES or MAX_ITERATIONS are worth keeping here too

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

_remote_debugging: No frame limit in get_async_stack_trace()

1 participant