Describe the bug
test_manage_read_window test fails with AttributeError: 'WebSocketServer' object has no attribute '_current_connection' due to a race condition.
The _current_connection attribute is never initialized in WebSocketServer.__init__(), while send_async() method immediately tries to access _current_connection without waiting for a client to connect
There's a race between when the client connects and when the server's _run_connection() method sets _current_connection.
Failure log:
======================================================================
FAIL: test_manage_read_window (test.test_websocket.TestClient.test_manage_read_window)
----------------------------------------------------------------------
Traceback (most recent call last):
File "/builddir/build/BUILD/python-awscrt-0.27.2-build/awscrt-0.27.2/test/test_websocket.py", line 544, in test_manage_read_window
server.send_async(msg)
~~~~~~~~~~~~~~~~~^^^^^
File "/builddir/build/BUILD/python-awscrt-0.27.2-build/awscrt-0.27.2/test/test_websocket.py", line 184, in send_async
while self._current_connection is None:
^^^^^^^^^^^^^^^^^^^^^^^^
AttributeError: 'WebSocketServer' object has no attribute '_current_connection'. Did you mean: '_run_connection'?
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/builddir/build/BUILD/python-awscrt-0.27.2-build/awscrt-0.27.2/test/test_websocket.py", line 534, in test_manage_read_window
with WebSocketServer(self.host, self.port) as server:
~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^
File "/builddir/build/BUILD/python-awscrt-0.27.2-build/awscrt-0.27.2/test/test_websocket.py", line 145, in __exit__
assert (self._server_thread.is_alive() == False)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
AssertionError
----------------------------------------------------------------------
Regression Issue
Expected Behavior
Test test_manage_read_window always pass.
Current Behavior
Test test_manage_read_window can fail due to race condition.
Reproduction Steps
The bug shows up or not depending on the timing between the main test thread and the asyncio server thread. The race condition becomes more likely under system load, in CI environments, on multi-core systems, or when there are network/scheduling delays that affect asyncio task execution order. The timing window is typically very small, making the failure intermittent and difficult to reproduce consistently.
Possible Solution
Initialize _current_connection = None in constructor and wait for connection establishment in send_async().
Additional Information/Context
No response
aws-crt-python version used
0.27.6
Python version used
Python 3.14.0rc2
Operating System and version
Fedora Rawhide
Describe the bug
test_manage_read_windowtest fails withAttributeError: 'WebSocketServer' object has no attribute '_current_connection'due to a race condition.The
_current_connectionattribute is never initialized inWebSocketServer.__init__(), whilesend_async()method immediately tries to access_current_connectionwithout waiting for a client to connectThere's a race between when the client connects and when the server's
_run_connection()method sets_current_connection.Failure log:
Regression Issue
Expected Behavior
Test
test_manage_read_windowalways pass.Current Behavior
Test
test_manage_read_windowcan fail due to race condition.Reproduction Steps
The bug shows up or not depending on the timing between the main test thread and the asyncio server thread. The race condition becomes more likely under system load, in CI environments, on multi-core systems, or when there are network/scheduling delays that affect asyncio task execution order. The timing window is typically very small, making the failure intermittent and difficult to reproduce consistently.
Possible Solution
Initialize
_current_connection = Nonein constructor and wait for connection establishment insend_async().Additional Information/Context
No response
aws-crt-python version used
0.27.6
Python version used
Python 3.14.0rc2
Operating System and version
Fedora Rawhide