Bug 8256 - Using asyncio's StreamReaderProtocol is risky
Summary: Using asyncio's StreamReaderProtocol is risky
Status: NEW
Alias: None
Product: ThinLinc
Classification: Unclassified
Component: Other (show other bugs)
Version: trunk
Hardware: PC Unknown
: P2 Normal
Target Milestone: LowPrio
Assignee: Bugzilla mail exporter
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-11-21 13:40 CET by Frida Flodin
Modified: 2023-11-28 13:05 CET (History)
0 users

See Also:
Acceptance Criteria:


Attachments

Description Frida Flodin cendio 2023-11-21 13:40:00 CET
There is a bug in asyncio's StreamReaderProtocol that can result in the garbage collector destroying tasks before they are done [1]. The affected asyncio high-level calls that we know of are: 
- open_connection
- start_server
- open_unix_connection
- start_unix_server

Today, we only use 'open_connection' and 'open_unix_connection' in portopencheck, but we do not wait for any data from those connections. To trigger the bug, the garbage collector must run when we wait for new data by, for example 'await streamreader.read()'. This bug shouldn't affect us right now, but we need to be careful when writing new code if the bug isn't fixed upstream.

[1] https://github.com/python/cpython/issues/91887
Comment 1 Pierre Ossman cendio 2023-11-21 13:59:48 CET
Note that this doesn't affect asyncio.create_subprocess_exec() even though it uses the stream API. The reason is that the bug is in StreamReaderProtocol, not StreamRead, and asyncio.create_subprocess_exec() uses its own protocol class.

Note You need to log in before you can comment on or make changes to this bug.