Skip to content
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

Retry on WANT_WRITE & WANT_READ in sendall() #954

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -225,6 +225,10 @@ Deprecations:
Changes:
^^^^^^^^

- Fixed the inability of ``OpenSSL.SSL.Connection.sendall()`` to
keep with sending data over the wire after ``SSL_ERROR_WANT_READ``
Copy link
Author

Choose a reason for hiding this comment

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

Suggested change
keep with sending data over the wire after ``SSL_ERROR_WANT_READ``
keep sending data over the wire after ``SSL_ERROR_WANT_READ``

or ``SSL_ERROR_WANT_WRITE`` is returned by ``SSL_write()``.
`#176 <https://github.com/pyca/pyopenssl/pull/176>`_
- Added a new optional ``chain`` parameter to ``OpenSSL.crypto.X509StoreContext()``
where additional untrusted certificates can be specified to help chain building.
`#948 <https://github.com/pyca/pyopenssl/pull/948>`_
Expand Down
9 changes: 8 additions & 1 deletion src/OpenSSL/SSL.py
Original file line number Diff line number Diff line change
Expand Up @@ -2053,7 +2053,14 @@
result = _lib.SSL_write(
self._ssl, data + total_sent, min(left_to_send, 2147483647)
)
self._raise_ssl_error(self._ssl, result)
try:
self._raise_ssl_error(self._ssl, result)
except (WantReadError, WantWriteError):
# NOTE: The use of SSL_MODE_ENABLE_PARTIAL_WRITE
# NOTE: above guarantees that in case of failure
# NOTE: no bytes have been written so we don't need
# NOTE: to update the counters, just need to retry.
continue

Check warning on line 2063 in src/OpenSSL/SSL.py

View check run for this annotation

Codecov / codecov/patch

src/OpenSSL/SSL.py#L2063

Added line #L2063 was not covered by tests
total_sent += result
left_to_send -= result

Expand Down