Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions Lib/test/test_external_inspection.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import asyncio
import unittest
import os
import textwrap
Expand Down Expand Up @@ -440,6 +441,22 @@ def _extract_coroutine_stacks_lineno_only(self, stack_trace):

@requires_remote_subprocess_debugging()
class TestSelfStackTrace(RemoteInspectionTestBase):
@skip_if_not_supported
def test_long_task_name_is_truncated(self):
# gh-157788
async def main():
asyncio.create_task(asyncio.sleep(10_000), name="x" * 300)
await asyncio.sleep(0)
return [
task.task_name
for info in RemoteUnwinder(os.getpid()).get_all_awaited_by()
for task in info.awaited_by
]

names = asyncio.run(main())
self.assertIn("Task-1", names)
self.assertEqual([len(n) for n in names if n.startswith("x")], [255])

@skip_if_not_supported
@unittest.skipIf(
sys.platform == "linux" and not PROCESS_VM_READV_SUPPORTED,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix ``python -m asyncio ps`` failing on a process that has a task with a
name longer than 255 characters.
6 changes: 5 additions & 1 deletion Modules/_remote_debugging/object_reading.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,12 +64,16 @@ read_py_str(
}

Py_ssize_t len = GET_MEMBER(Py_ssize_t, unicode_obj, unwinder->debug_offsets.unicode_object.length);
if (len < 0 || len > max_len) {
if (len < 0) {
PyErr_Format(PyExc_RuntimeError,
"Invalid string length (%zd) at 0x%lx", len, address);
set_exception_cause(unwinder, PyExc_RuntimeError, "Invalid string length in remote Unicode object");
return NULL;
}
if (len > max_len) {
// gh-157788: a long name must not fail the whole read
len = max_len;
}

// Inspect state to pick the right data offset and character width.
// We rely on the remote process sharing this Python version's
Expand Down
Loading