Skip to content

test_asyncio test_remote_shutdown_receives_trailing_data_on_slow_socket can fail with AttributeError on a slow socket #151522

@itamaro

Description

@itamaro

Bug report

Bug description:

test.test_asyncio.test_ssl.TestSSL.test_remote_shutdown_receives_trailing_data_on_slow_socket reads the SSL protocol's underlying transport and patches its write:

socket_transport = writer.transport._ssl_protocol._transport
...
with unittest.mock.patch.object(
    socket_transport, "write",
    wraps=socket_transport.write,
    side_effect=_fake_full_write_buffer
):

Immediately before this, the test fills the write backlog and reads until the remote shuts the connection down (catching BrokenPipeError / ConnectionResetError).
On a slow or loaded socket the remote shutdown can complete first, and connection_lost clears _SSLProtocolTransport's underlying transport (_ssl_protocol._transport becomes None), but the test still performs an attribute lookup:

Traceback (most recent call last):
  File ".../test/test_asyncio/test_ssl.py", line ..., in client
    wraps=socket_transport.write,
          ^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'NoneType' object has no attribute 'write'

This is a timing-dependent flake: the test assumes the underlying transport is still alive at this point.

CPython versions tested on:

CPython main branch, 3.16, 3.15, 3.14

Operating systems tested on:

Linux

Linked PRs

Metadata

Metadata

Assignees

Labels

testsTests in the Lib/test dirtype-bugAn unexpected behavior, bug, or error
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions