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

ssl.SSLWantReadError: The operation did not complete (read) #87

Closed
altherat opened this issue Sep 8, 2018 · 5 comments · Fixed by #100
Closed

ssl.SSLWantReadError: The operation did not complete (read) #87

altherat opened this issue Sep 8, 2018 · 5 comments · Fixed by #100

Comments

@altherat
Copy link

altherat commented Sep 8, 2018

I'm using OkHttpClient on Android to connect to my websocket server. When my app establishes a connection, I send a message. Shorter messages don't have an issue, but for longer messages I'm getting an exception. The message I'm testing with is 14819 characters long in JSON format, but I've tested some smaller messages and the exception starts appearing when it's around 4315 characters long. The culprit is this line.

Here's the stack trace:

  File "/usr/local/lib/python3.5/dist-packages/SimpleWebSocketServer/SimpleWebSocketServer.py", line 274, in _handleData
    data = self.client.recv(16384)
  File "/usr/lib/python3.5/ssl.py", line 914, in recv
    return self.read(buflen)
  File "/usr/lib/python3.5/ssl.py", line 791, in read
    return self._sslobj.read(len, buffer)
  File "/usr/lib/python3.5/ssl.py", line 577, in read
    v = self._sslobj.read(len)
ssl.SSLWantReadError: The operation did not complete (read) (_ssl.c:1977)

I don't know the protocol well so it's hard for me to tell whether it's the fault of this library or OkHttpClient or maybe I'm just doing something wrong. The only thing I've tried is increasing the 16384 to a higher number but it didn't help.

@uzlonewolf
Copy link

This looks like https://bugs.python.org/issue12343 . Try replacing the data = self.client.recv(16384) with

         try:
            data = self.client.recv(16384)
         except ssl.SSLWantReadError:
            return

@dpallot
Copy link
Owner

dpallot commented Feb 7, 2019

This looks like https://bugs.python.org/issue12343 . Try replacing the data = self.client.recv(16384) with

         try:
            data = self.client.recv(16384)
         except ssl.SSLWantReadError:
            return

If its working would you like to put in a pull request?

@uzlonewolf
Copy link

Unfortunately I have not been able to test any of this as I have not run into this problem myself. There also seems to be very little documentation about this issue, and one of the few comments I've seen says select() is not going to fire when the data does arrive, so I'm hesitant to commit code I can't verify works. I have some ideas on a test setup to try and reproduce this but have not found the time to set it up.

@eaganr
Copy link

eaganr commented Mar 10, 2020

This project has been really helpful. Ran into a similar problem as in this thread. The SSL websocket was closing when a large amount of data was sent. I found a solution. I got rid of the else statement at line 341. Then the while loop sending data retries until it is successful rather than closing the socket.

@uzlonewolf
Copy link

uzlonewolf commented Mar 10, 2020

I don't like blindly ignoring all errors as on an unclean close the socket is going to hang and stick around forever and block all other clients while it does it. What is the exact exception thrown? Adding it to the list of try-again exceptions would be better.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants