Python 3.11.1: async subprocess stdout lost when piped

I noticed behavior in Python 3.11.1 that is inconsistent with earlier versions. I’d appreciate if someone tried to reproduce this.

Minimal example:

import asyncio


async def get_command_stdout(cmd, *args):
    proc = await asyncio.create_subprocess_exec(
        cmd, *args, stdout=asyncio.subprocess.PIPE,
    )
    stdout, _ = await proc.communicate()
    return stdout


async def main():
    return await asyncio.gather(
        get_command_stdout('echo', 'foo'),
        get_command_stdout('echo', 'bar'),
    )


if __name__ == '__main__':
    print(asyncio.run(main()))

In Python 3.10.9 and 3.11.0 the result is always as I would expect, i.e.

[b'foo\n', b'bar\n']

however in Python 3.11.1 I am constantly getting

[b'', b'bar\n']

I suspect this might be a bug/regression.

All Python versions mentioned above were built with pyenv on Ubuntu 22.04.

Additional info:

  1. in Python 3.12.0a3 the same problem occurs, i.e. the first command’s stdout is lost in the pipe
  2. in all tested Python versions, if the subprocess stdout is not piped, the script’s output is as expected, i.e.
    foo
    bar
    [None, None]
    
  3. in all tested Python versions, if I rewrite the code to synchronous, the result is correct, i.e. [b'foo\n', b'bar\n']

I can reproduce this on my machine, adding extra commands shows that only the output of the last command is correct.

Could you file an issue about this on github?

@ronaldoussoren Thanks for your response. Someone already opened an issue: