-
Notifications
You must be signed in to change notification settings - Fork 142
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed mishandling of large buffers in BaseSocket.sendall()
Fixes #38.
- Loading branch information
Showing
3 changed files
with
26 additions
and
5 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -72,6 +72,23 @@ async def server(): | |
|
||
assert response == b'blahbleh' | ||
|
||
@pytest.mark.anyio | ||
async def test_send_large_buffer(self): | ||
async def server(): | ||
async with await stream_server.accept() as stream: | ||
await stream.send_all(buffer) | ||
|
||
buffer = b'\xff' * 1024 # should exceed the maximum kernel send buffer size | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
agronholm
Author
Owner
|
||
async with create_task_group() as tg: | ||
async with await create_tcp_server(interface='localhost') as stream_server: | ||
await tg.spawn(server) | ||
async with await connect_tcp('localhost', stream_server.port) as client: | ||
response = await client.receive_exactly(len(buffer)) | ||
with pytest.raises(IncompleteRead): | ||
await client.receive_exactly(1) | ||
|
||
assert response == buffer | ||
|
||
@pytest.mark.parametrize('method_name, params', [ | ||
('receive_until', [b'\n', 100]), | ||
('receive_exactly', [5]) | ||
|
1024 bytes is nowhere near the maximum kernel send buffer size. On my laptop, a new socketpair accepts >200 KB in its first call to
send
. (And modern kernels like to dynamically resize buffers, so that another kernel might accept more or less.) You probably want, like, multiple megabytes here, and possibly to mess withSO_SNDBUF
as well.