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

Handle OpenSSL.SSL.WantReadError and WantWriteError in pyopenssl adapter #332

Open
wants to merge 2 commits into
base: main
Choose a base branch
from

Conversation

vashek
Copy link

@vashek vashek commented Nov 2, 2020

❓ What kind of change does this PR introduce?

  • 🐞 bug fix
  • 🐣 feature
  • πŸ“‹ docs update
  • πŸ“‹ tests/coverage improvement
  • πŸ“‹ refactoring
  • πŸ’₯ other

πŸ“‹ What is the related issue number (starting with #)

Fixes #245

❓ What is the current behavior? (You can also link to an open issue here)

❓ What is the new behavior (if this is a feature change)?

πŸ“‹ Other information:

πŸ“‹ Checklist:

  • I think the code is well written
  • I wrote good commit messages
  • I have squashed related commits together after the changes have been approved
  • Unit tests for the changes exist
  • Integration tests for the changes exist (if applicable)
  • I used the same coding conventions as the rest of the project
  • The new code doesn't generate linter offenses
  • Documentation reflects the changes
  • The PR relates to only one subject with a clear title
    and description in grammatically correct, complete sentences

This change is Reviewable

@webknjaz webknjaz linked an issue Nov 2, 2020 that may be closed by this pull request
3 tasks
cheroot/makefile.py Outdated Show resolved Hide resolved
@webknjaz webknjaz changed the title fixes #245 - handle OpenSSL.SSL.WantReadError and WantWriteError Handle OpenSSL.SSL.WantReadError and WantWriteError in pyopenssl adapter Nov 2, 2020
cheroot/ssl/pyopenssl.py Outdated Show resolved Hide resolved
cheroot/ssl/pyopenssl.py Outdated Show resolved Hide resolved
cheroot/ssl/pyopenssl.py Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

webknjaz commented Nov 2, 2020

@vashek have you considered fixing pyopenssl itself? pyca/pyopenssl#176 (comment)

Comment on lines 161 to 169
def sendall(self, *args, **kwargs):
"""Send whole message to the socket.

Not supported due to https://github.com/pyca/pyopenssl/issues/176.
Until that bug is fixed, sendall() may throw SSL.WantWriteError, but
there is no correct way to retry the call because we don't know how
many bytes were already transmitted. We could work around this by
reimplementing sendall() using send(), but we don't actually use
sendall() anywhere.
"""
raise NotImplementedError('sendall() is unsupported by pyOpenSSL')
Copy link
Member

Choose a reason for hiding this comment

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

How about taking https://github.com/pyca/pyopenssl/blob/124a013/src/OpenSSL/SSL.py#L1649-L1677 and adding retries and then resubmitting the fix to the upstream too?

Copy link
Member

Choose a reason for hiding this comment

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

Another interesting code snippet: Lawouach/WebSocket-for-Python#174 (comment).

cheroot/ssl/pyopenssl.py Outdated Show resolved Hide resolved
Comment on lines 168 to 169
reimplementing sendall() using send(), but we don't actually use
sendall() anywhere.
Copy link
Member

Choose a reason for hiding this comment

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

When you say "we don't use" do you mean not even some internal calls hit it? How do we get the error, then?

Copy link
Author

Choose a reason for hiding this comment

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

We don't, as far as I know, it's just something I noticed while googling the WantWriteError issue.
There is no occurrence of sendall in the whole cheroot project, other than in pyopenssl.py. (Also, my server seems to work with this change.)

Copy link
Member

Choose a reason for hiding this comment

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

Well, if it's unrelated to the PR, it should be in a separate PR.

@webknjaz webknjaz added the bug Something is broken label Nov 2, 2020
cheroot/ssl/pyopenssl.py Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

webknjaz commented Nov 2, 2020

Hm... it looks like sendall was used as write() + flush() at some point but then got replaced with write: 60cd709 / a0b1d01.

@webknjaz
Copy link
Member

webknjaz commented Nov 2, 2020

Some jobs are failing because of a deprecation warning in cryptography. I've fixed that on master. To get the changes, rebase this PR branch.

@vashek vashek force-pushed the bugfix/245-openssl-exceptions branch from f4b713b to add128a Compare November 4, 2020 14:43
cheroot/ssl/pyopenssl.py Outdated Show resolved Hide resolved
@webknjaz
Copy link
Member

webknjaz commented Nov 4, 2020

Do you think this can be tested somehow?

@webknjaz
Copy link
Member

webknjaz commented Nov 4, 2020

@vashek so what do you think about tests?

@webknjaz
Copy link
Member

The test will probably need to make the sending and/or receiving socket full like I tried here: https://github.com/pyca/pyopenssl/pull/955/files#diff-5fbedfbbf8f0780aeee680927973f302330dc10fe915c7e7deecf4b0556c492cR3157

@vashek
Copy link
Author

vashek commented Apr 15, 2021

Sorry for letting this rot. Quite honestly, I'd appreciate if someone could help with the tests - or accept it without them.

@vashek
Copy link
Author

vashek commented Feb 8, 2022

Any chance of accepting this?

@webknjaz
Copy link
Member

@vashek I suppose it's hard to write tests for this which is why I'll probably accept it without tests. But #245 (comment) seems to imply that it may be causing problems for retries. Do you have any thoughts on that?

@webknjaz webknjaz force-pushed the bugfix/245-openssl-exceptions branch from bab03e9 to 6fe20d2 Compare March 17, 2023 18:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something is broken
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Unhandled OpenSSL.SSL.WantReadError and WantWriteError raised by PyOpenSSL
2 participants