Skip to content

bpo-35589: Prevent buffer copy in sock_sendall() #11418

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
May 16, 2019

Conversation

asvetlov
Copy link
Contributor

@asvetlov asvetlov commented Jan 2, 2019

No NEWs is needed since the problem was introduced on master only and never released.

https://bugs.python.org/issue35589

Copy link
Contributor

@eamanu eamanu left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@eamanu
Copy link
Contributor

eamanu commented Jan 3, 2019

Some tests are not required?

@asvetlov
Copy link
Contributor Author

asvetlov commented Jan 3, 2019

There are tests for sending large data already.
An explicit test for memory consumption is not robust.
We can add a mocked test but the test is useless almost: it checks mocks correctness only :)


fut = self.create_future()
fd = sock.fileno()
fut.add_done_callback(
functools.partial(self._sock_write_done, fd))
self.add_writer(fd, self._sock_sendall, fut, sock, data)
# use a trick with a list in closure to store a mutable state
self.add_writer(fd, self._sock_sendall, fut, sock, data, [n])
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But why do we want to have a mutable state here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I cannot pass just n -- need either a mutable object or re-add a writer after every sock.send() call until all data is sent.

Copy link
Member

@methane methane left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Theorically speaking, memoryview should be closed after using.
But it is ignored often. Unlike file.close(), not closing memoryview is not a real problem on PyPy.

I want portable version of os.pwrite(fd, buf, start), instead of abusing memoryview though...

@miss-islington miss-islington merged commit 6e78900 into python:master May 16, 2019
@asvetlov
Copy link
Contributor Author

Sorry, forgot to merge it 3 months ago

@asvetlov asvetlov deleted the fast-sendall branch May 16, 2019 13:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants