@@ -23,8 +23,12 @@ async def test_malformed_initialize_request_does_not_crash_server():
2323 instead of crashing the server (HackerOne #3156202).
2424 """
2525 # Create in-memory streams for testing
26- read_send_stream , read_receive_stream = anyio .create_memory_object_stream (10 )
27- write_send_stream , write_receive_stream = anyio .create_memory_object_stream (10 )
26+ read_send_stream , read_receive_stream = anyio .create_memory_object_stream [
27+ SessionMessage | Exception
28+ ](10 )
29+ write_send_stream , write_receive_stream = anyio .create_memory_object_stream [
30+ SessionMessage
31+ ](10 )
2832
2933 # Create a malformed initialize request (missing required params field)
3034 malformed_request = JSONRPCRequest (
@@ -90,6 +94,10 @@ async def test_malformed_initialize_request_does_not_crash_server():
9094
9195 except anyio .WouldBlock :
9296 pytest .fail ("No response received - server likely crashed" )
97+
98+ # Close the send streams to signal end of communication
99+ await read_send_stream .aclose ()
100+ await write_send_stream .aclose ()
93101
94102
95103@pytest .mark .anyio
@@ -98,8 +106,12 @@ async def test_multiple_concurrent_malformed_requests():
98106 Test that multiple concurrent malformed requests don't crash the server.
99107 """
100108 # Create in-memory streams for testing
101- read_send_stream , read_receive_stream = anyio .create_memory_object_stream (100 )
102- write_send_stream , write_receive_stream = anyio .create_memory_object_stream (100 )
109+ read_send_stream , read_receive_stream = anyio .create_memory_object_stream [
110+ SessionMessage | Exception
111+ ](100 )
112+ write_send_stream , write_receive_stream = anyio .create_memory_object_stream [
113+ SessionMessage
114+ ](100 )
103115
104116 # Start a server session
105117 async with ServerSession (
@@ -145,4 +157,8 @@ async def test_multiple_concurrent_malformed_requests():
145157 for i , response in enumerate (error_responses ):
146158 assert isinstance (response , JSONRPCError )
147159 assert response .id == f"malformed_{ i } "
148- assert response .error .code == INVALID_PARAMS
160+ assert response .error .code == INVALID_PARAMS
161+
162+ # Close the send streams to signal end of communication
163+ await read_send_stream .aclose ()
164+ await write_send_stream .aclose ()
0 commit comments