Skip to content

gh-145541: Fix InvalidStateError in BaseSubprocessTransport._call_connection_lost()#145554

Merged
kumaraditya303 merged 1 commit intopython:mainfrom
daandemeyer:fix
Mar 9, 2026
Merged

gh-145541: Fix InvalidStateError in BaseSubprocessTransport._call_connection_lost()#145554
kumaraditya303 merged 1 commit intopython:mainfrom
daandemeyer:fix

Conversation

@daandemeyer
Copy link
Contributor

@daandemeyer daandemeyer commented Mar 5, 2026

Change if not waiter.cancelled() to if not waiter.done() in both
_try_finish() and _call_connection_lost() so that waiters whose result
was already set by _try_finish() are not set again by
_call_connection_lost(), which would raise InvalidStateError.

When _connect_pipes is cancelled (e.g. by SIGINT during subprocess
creation), _pipes_connected stays False. If the process then exits,
_try_finish() sets the result on exit waiters because _pipes_connected
is False, and then schedules _call_connection_lost() because all pipes
are disconnected. _call_connection_lost() must skip waiters that are
already done.

@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2026

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.

@python-cla-bot
Copy link

python-cla-bot bot commented Mar 5, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

@vstinner
Copy link
Member

vstinner commented Mar 5, 2026

Please set a more useful title than "wip" for your PR draft.

@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2026

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.

@daandemeyer daandemeyer changed the title gh-145541: wip gh-145541: Fix InvalidStateError in BaseSubprocessTransport._call_connection_lost() Mar 5, 2026
@daandemeyer daandemeyer marked this pull request as ready for review March 5, 2026 18:16
@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2026

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.

@daandemeyer
Copy link
Contributor Author

Ping @kumaraditya303

…ll_connection_lost()

Change `if not waiter.cancelled()` to `if not waiter.done()` in both
_try_finish() and _call_connection_lost() so that waiters whose result
was already set by _try_finish() are not set again by
_call_connection_lost(), which would raise InvalidStateError.

When _connect_pipes is cancelled (e.g. by SIGINT during subprocess
creation), _pipes_connected stays False. If the process then exits,
_try_finish() sets the result on exit waiters because _pipes_connected
is False, and then schedules _call_connection_lost() because all pipes
are disconnected. _call_connection_lost() must skip waiters that are
already done.
@kumaraditya303 kumaraditya303 added topic-asyncio needs backport to 3.13 bugs and security fixes needs backport to 3.14 bugs and security fixes labels Mar 9, 2026
@kumaraditya303 kumaraditya303 merged commit 1564e23 into python:main Mar 9, 2026
57 checks passed
@miss-islington-app
Copy link

Thanks @daandemeyer for the PR, and @kumaraditya303 for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13, 3.14.
🐍🍒⛏🤖

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 9, 2026
…_call_connection_lost()` (pythonGH-145554)

(cherry picked from commit 1564e231aae7afad5b9b19a277d1efff2b840ad2)

Co-authored-by: Daan De Meyer <daan.j.demeyer@gmail.com>
miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 9, 2026
…_call_connection_lost()` (pythonGH-145554)

(cherry picked from commit 1564e231aae7afad5b9b19a277d1efff2b840ad2)

Co-authored-by: Daan De Meyer <daan.j.demeyer@gmail.com>
@bedevere-app
Copy link

bedevere-app bot commented Mar 9, 2026

GH-145676 is a backport of this pull request to the 3.14 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.14 bugs and security fixes label Mar 9, 2026
@bedevere-app
Copy link

bedevere-app bot commented Mar 9, 2026

GH-145677 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 9, 2026
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.

3 participants