Skip to content

Fix 1850#1862

Merged
oberstet merged 2 commits into
crossbario:masterfrom
oberstet:fix_1850
Jun 17, 2026
Merged

Fix 1850#1862
oberstet merged 2 commits into
crossbario:masterfrom
oberstet:fix_1850

Conversation

@oberstet

Copy link
Copy Markdown
Contributor

fixes #1850

oberstet added 2 commits June 17, 2026 10:12
…rio#1850)

The Twisted WampRawSocketProtocol.abort() guarded on isOpen(), which
requires an attached WAMP session. During the opening handshake no
session exists yet, so a handshake failure (invalid magic byte from a
port scanner / service probe, or no suitable serializer) made abort()
take the else-branch and raise TransportLost. That exception escaped
through dataReceived into the Twisted reactor and was logged as an
"Unhandled Error" with a full stack trace, while the TCP connection
stayed open.

Fix:

- abort() now guards on `self.transport is not None` instead of
  isOpen(): aborting a transport does not require an open WAMP session,
  only a transport. A genuinely missing transport still raises
  TransportLost. Post-handshake callers (stringReceived error paths,
  _on_handshake_complete) are unaffected, since an open session always
  has a transport.
- The four handshake-failure sites (server/client x bad-magic/
  no-serializer) now `return` after abort(). Previously they relied on
  abort() raising to stop processing; without the return they would
  fall through and continue the handshake (e.g. write a reply and start
  a session) on an aborted connection.

The asyncio backend already handled this correctly (parse_handshake
raises HandshakeError, caught in data_received -> protocol_error closes
the transport and returns). Added cross-backend regression tests for
both Twisted and asyncio, server and client.

Fixes crossbario#1850.

Note: abort() is part of ITransport; this changes its behavior in the
pre-session state from raising TransportLost to closing the transport.
Flagging for careful human review per AI_POLICY.md.

Note: This work was completed with AI assistance (Claude Code).
@oberstet oberstet merged commit f005049 into crossbario:master Jun 17, 2026
35 checks passed
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.

[BUG] WampRawSocketServerProtocol leaks TransportLost from dataReceived on bad magic byte (logged by Twisted as Unhandled Error)

1 participant