Skip to content

gh-162217: Shield shared stdin close future to avoid InvalidStateError - #162284

Open
mathisbusanabussei359-web wants to merge 1 commit into
python:mainfrom
mathisbusanabussei359-web:gh-162217-fix-stdin-wait-closed
Open

mathisbusanabussei359-web wants to merge 1 commit into
python:mainfrom
mathisbusanabussei359-web:gh-162217-fix-stdin-wait-closed

Conversation

@mathisbusanabussei359-web

@mathisbusanabussei359-web mathisbusanabussei359-web commented Nov 19, 2026 •

Copy link
Copy Markdown

Fixes #162217

Cancelling a task that is awaiting proc.stdin.wait_closed() was
cancelling the shared _stdin_closed future. When the real close
happened later, pipe_connection_lost tried to set the result on an
already-cancelled future → InvalidStateError.

Solution: return tasks.shield(self._stdin_closed) so that cancelling
one waiter does not affect the shared future.

Added a regression test that creates two waiters, cancels one, then
closes stdin and checks that the remaining waiter succeeds and no
exception handler is triggered.

…reamProtocol

Cancelling one waiter on stdin.wait_closed() must not cancel the shared future used by pipe_connection_lost()
@python-cla-bot

python-cla-bot Bot commented Nov 19, 2026 •

Copy link
Copy Markdown

All commit authors signed the Contributor License Agreement.

CLA signed

@bedevere-app

bedevere-app Bot commented Nov 19, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

asyncio: cancelling a task awaiting subprocess stdin.wait_closed() cancels the shared close future, then pipe_connection_lost() raises InvalidStateError

1 participant