This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author asvetlov
Recipients asvetlov, bluecarrot, yselivanov
Date 2022-01-29.09:01:39
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1643446899.76.0.102275094759.issue46568@roundup.psfhosted.org>
In-reply-to
Content
Your code has at least one concurrency problem. Let's look back at forward_stream() function:

async def forward_stream(reader: StreamReader, writer: StreamWriter, event: asyncio.Event, source: str):
    writer_drain = writer.drain()  # <--- awaitable is created here
    while not event.is_set():
        try:
            data = await asyncio.wait_for(reader.read(1024), 1)  # <-- CancelledError can be caught here, stack unwinds and writer_drain is never awaited, sure.
        except asyncio.TimeoutError:
            continue
     ...  # the rest is not important for this case

To solve the problem, you should create writer_drain *before its awaiting*, not before another 'await' call.
History
Date User Action Args
2022-01-29 09:01:39asvetlovsetrecipients: + asvetlov, yselivanov, bluecarrot
2022-01-29 09:01:39asvetlovsetmessageid: <1643446899.76.0.102275094759.issue46568@roundup.psfhosted.org>
2022-01-29 09:01:39asvetlovlinkissue46568 messages
2022-01-29 09:01:39asvetlovcreate