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

Need to exception for "SSLEOFError" on python 3.10, 3.11, 3.12 #3382

Closed
keepworking opened this issue Apr 14, 2024 · 3 comments
Closed

Need to exception for "SSLEOFError" on python 3.10, 3.11, 3.12 #3382

keepworking opened this issue Apr 14, 2024 · 3 comments

Comments

@keepworking
Copy link

Subject

Last time, I found an error in cpython ssl module that all OSError changes to SSLEOFError, and I fixed it.
Please refer to the following link for more information.
python/cpython#115627

Urlib3 is also affected by this error, and exceptions are required for versions that still have this error.

There will be a few more errors affected, but what I have identified is the next issue.
#3148

You will be able to find out more by the following test code.

import http.client
import requests

try :
    print("START send http.client.HTTPSConnection")
    http.client.HTTPSConnection("google.com").request('POST', '/', body=b'A'*1000000)
    print("END send http.client.HTTPSConnection")
except Exception as e:
    print(e)

try :
    print("START send requests.post")
    requests.post('https://google.com/', data=b'A'*1000000)
    print("END send requests.post")
except Exception as e:
    print(e)
orange@32thread-server:~/project/pythonssleof$ python3.9 main.py
START send http.client.HTTPSConnection
[Errno 32] Broken pipe # got a broken pipe
START send requests.post
END send requests.post # requests(urllib3) did not throw a error
orange@32thread-server:~/project/pythonssleof$ python3.10 main.py
START send http.client.HTTPSConnection
EOF occurred in violation of protocol (_ssl.c:2426) # broekn pipe changed to EOF error
START send requests.post
HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2426)'))) # requests(urllib3) throwed a error
orange@32thread-server:~/project/pythonssleof$

This is related to the following code in urllib3.

https://github.com/urllib3/urllib3/blob/main/src/urllib3/connectionpool.py#L492-L517

        # conn.request() calls http.client.*.request, not the method in
        # urllib3.request. It also calls makefile (recv) on the socket.
        try:
            conn.request(
                method,
                url,
                body=body,
                headers=headers,
                chunked=chunked,
                preload_content=preload_content,
                decode_content=decode_content,
                enforce_content_length=enforce_content_length,
            )

        # We are swallowing BrokenPipeError (errno.EPIPE) since the server is
        # legitimately able to close the connection after sending a valid response.
        # With this behaviour, the received response is still readable.
        except BrokenPipeError:
            pass
        except OSError as e:
            # MacOS/Linux
            # EPROTOTYPE and ECONNRESET are needed on macOS
            # https://erickt.github.io/blog/2014/11/19/adventures-in-debugging-a-potential-osx-kernel-bug/
            # Condition changed later to emit ECONNRESET instead of only EPROTOTYPE.
            if e.errno != errno.EPROTOTYPE and e.errno != errno.ECONNRESET:
                raise

If the server shuts down with a response while sending large request data, an error will occur in that area.

The fix for the cpython bug will not be backported on 3.10, 3.11, and 3.12 is undecided, but it will not be backported. There are likely to be other related errors, so further analysis is needed.

Environment

Describe your environment.
At least, paste here the output of:

>>> import platform
>>> import ssl
>>> import urllib3
>>>
>>> print("OS", platform.platform())
OS Linux-6.5.0-26-generic-x86_64-with-glibc2.35
>>> print("Python", platform.python_version())
Python 3.10.12
>>> print(ssl.OPENSSL_VERSION)
OpenSSL 3.0.2 15 Mar 2022
>>> print("urllib3", urllib3.__version__)
urllib3 1.26.5

Steps to Reproduce

import http.client
import requests

try :
    print("START send http.client.HTTPSConnection")
    http.client.HTTPSConnection("google.com").request('POST', '/', body=b'A'*1000000)
    print("END send http.client.HTTPSConnection")
except Exception as e:
    print(e)

try :
    print("START send requests.post")
    requests.post('https://google.com/', data=b'A'*1000000)
    print("END send requests.post")
except Exception as e:
    print(e)

Expected Behavior

orange@32thread-server:~/project/pythonssleof$ python3.9 main.py
START send http.client.HTTPSConnection
[Errno 32] Broken pipe # got a broken pipe
START send requests.post
END send requests.post # requests(urllib3) did not throw a error

Actual Behavior

orange@32thread-server:~/project/pythonssleof$ python3.10 main.py
START send http.client.HTTPSConnection
EOF occurred in violation of protocol (_ssl.c:2426) # broekn pipe changed to EOF error
START send requests.post
HTTPSConnectionPool(host='google.com', port=443): Max retries exceeded with url: / (Caused by SSLError(SSLEOFError(8, 'EOF occurred in violation of protocol (_ssl.c:2426)'))) # requests(urllib3) throwed a error
@sigmavirus24
Copy link
Contributor

Duplicate of #3100

@sigmavirus24 sigmavirus24 marked this as a duplicate of #3100 Apr 15, 2024
@sigmavirus24 sigmavirus24 closed this as not planned Won't fix, can't repro, duplicate, stale Apr 15, 2024
@keepworking
Copy link
Author

@sigmavirus24 i just write a comment on #3100.
Since they are the same EOF error message, they may seem like the same error, but they are different error messages. #3100 does not require any exceptions, but this issue does. I would appreciate it if you could open it again.

@mberdyshev
Copy link

I would appreciate it if you could open it again.

I agree. Would be great to continue work on this issue.

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

No branches or pull requests

3 participants