Skip to content

Fix TwistedConnection close() not setting last_error#703

Draft
dkropachev wants to merge 1 commit intomasterfrom
fix/twisted-close-race-614
Draft

Fix TwistedConnection close() not setting last_error#703
dkropachev wants to merge 1 commit intomasterfrom
fix/twisted-close-race-614

Conversation

@dkropachev
Copy link
Collaborator

Summary

Fixes TwistedConnection.close() not setting last_error when the connection is closed during setup.

  • When close() is called before connected_event is set, factory() could return a dead connection because last_error was never set
  • Twisted is not vulnerable to EBADF races (no raw socket I/O), but the factory() dead-connection bug affects it

Changes

  • Set last_error in close() when connected_event is not yet set (matching the asyncore pattern)

Test plan

  • tests/unit/io/test_twistedreactor.py passes

Refs #614

When close() is called during connection setup (before connected_event
is set), factory() could return a dead connection because last_error
was not set. Copy the pattern from asyncore where last_error is set
in close() when the connection handshake hasn't completed yet.
@dkropachev dkropachev marked this pull request as draft February 14, 2026 16:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant