Repository navigation
gh-153364: Make frame, coroutine, and task-waiter chain walks iterative and bounded #153365
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 8 commits
4dd6f49
e71aaa5
116da45
3e12939
c46810c
dd6e19a
0972e00
3c5f78b
78c18f9
21d764e
000287e
353f815
f66866b
c9f1ebd
7236ca2
35fc6c6
10149e9
ef51563
b5022ba
73b8674
e0607dc
ed731eb
75a8d8e
c0ce737
f3c80d4
4fd4027
f2530ec
0ab3342
2a444ec
ed95a2e
a1221fd
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,2 @@ | ||
| Add limits to frame and coroutine-chain walks in the Tachyon sampling | ||
| profiler. This avoids potential hangs. Patch by Maurycy Pawłowski-Wieroński. |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -147,6 +147,7 @@ typedef enum _WIN32_THREADSTATE { | |
| #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 */ | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. While we're at it, should |
||
|
|
||
| #ifndef MAX | ||
| #define MAX(a, b) ((a) > (b) ? (a) : (b)) | ||
|
|
@@ -732,7 +733,8 @@ extern int parse_task( | |
| extern int parse_coro_chain( | ||
| RemoteUnwinderObject *unwinder, | ||
| uintptr_t coro_address, | ||
| PyObject *render_to | ||
| PyObject *render_to, | ||
| size_t depth | ||
| ); | ||
|
|
||
| extern int parse_async_frame_chain( | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -305,9 +305,7 @@ process_frame_chain( | |||||||||
| uintptr_t frame_addr = ctx->frame_addr; | ||||||||||
| uintptr_t prev_frame_addr = 0; | ||||||||||
| uintptr_t last_frame_addr = 0; | ||||||||||
| const size_t MAX_FRAMES = 1024 + 512; | ||||||||||
| size_t frame_count = 0; | ||||||||||
| assert(MAX_FRAMES > 0 && MAX_FRAMES < 10000); | ||||||||||
|
|
||||||||||
| ctx->stopped_at_cached_frame = 0; | ||||||||||
| ctx->last_frame_visited = 0; | ||||||||||
|
|
@@ -318,12 +316,12 @@ process_frame_chain( | |||||||||
| uintptr_t stackpointer = 0; | ||||||||||
| last_frame_addr = frame_addr; | ||||||||||
|
|
||||||||||
| if (++frame_count > MAX_FRAMES) { | ||||||||||
| if (++frame_count > MAX_FRAME_CHAIN_DEPTH) { | ||||||||||
| PyErr_SetString(PyExc_RuntimeError, "Too many stack frames (possible infinite loop)"); | ||||||||||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Generally, there's more interplay between this issue and #154194, since we could return Similarly: cpython/Modules/_remote_debugging/code_objects.c Lines 445 to 448 in 46acb79
|
||||||||||
| set_exception_cause(unwinder, PyExc_RuntimeError, "Frame chain iteration limit exceeded"); | ||||||||||
| return -1; | ||||||||||
| } | ||||||||||
| assert(frame_count <= MAX_FRAMES); | ||||||||||
| assert(frame_count <= MAX_FRAME_CHAIN_DEPTH); | ||||||||||
|
|
||||||||||
| if (ctx->chunks && ctx->chunks->count > 0) { | ||||||||||
| if (parse_frame_from_chunks(unwinder, &frame, frame_addr, &next_frame_addr, &stackpointer, ctx->chunks) == 0) { | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.