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

Broken master build: SSL_WRONG_VERSION_NUMBER #276

Closed
florimondmanca opened this issue Feb 23, 2021 · 3 comments
Closed

Broken master build: SSL_WRONG_VERSION_NUMBER #276

florimondmanca opened this issue Feb 23, 2021 · 3 comments

Comments

@florimondmanca
Copy link
Member

florimondmanca commented Feb 23, 2021

We have a CI build error that I saw in the latest master build as well as some other branches, eg #275.

  • Not able to reproduce on my local macOS machine. CI uses Linux -> Can someone on Linux reproduce by running the test suite?
  • It happens in test_connection_timeout_tcp, which does something hacky: try to connect via HTTPS to generate a ConnectTimeout. In CI we get a ConnectError instead. Probably related to the underlying openssl version?

https://github.com/encode/httpcore/runs/1785395873?check_suite_focus=true#step:7:79

__________________ test_connection_timeout_tcp[asyncio-auto] ___________________

backend = 'auto'
server = <tests.utils.HypercornServer object at 0x7f7f41716810>

    @pytest.mark.skipif(
        sys.version_info[:2] < (3, 7),
        reason="Hypercorn doesn't support python < 3.7 (this test is local-only)",
    )
    @pytest.mark.anyio
    async def test_connection_timeout_tcp(backend: str, server: Server) -> None:
        # we try to access http server using https. It caused some SSL timeouts
        # in TLSStream.wrap inside inside AnyIOBackend.open_tcp_stream
        method = b"GET"
        url = (b"https", *server.netloc, b"/")
        headers = [server.host_header]
        ext = {"timeout": {"connect": 0.1}}
    
        async with httpcore.AsyncConnectionPool(backend=backend) as http:
            with pytest.raises(httpcore.ConnectTimeout):
>               await http.arequest(method, url, headers, ext=ext)

tests/async_tests/test_interfaces.py:487: 
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
httpcore/_async/connection_pool.py:259: in arequest
    socket = await self._open_socket(origin, timeout=timeout)
httpcore/_async/connection_pool.py:214: in _open_socket
    local_address=self._local_address,
httpcore/_backends/auto.py:45: in open_tcp_stream
    hostname, port, ssl_context, timeout, local_address=local_address
httpcore/_backends/asyncio.py:268: in open_tcp_stream
    connect_timeout,
/opt/hostedtoolcache/Python/3.7.9/x64/lib/python3.7/contextlib.py:130: in __exit__
    self.gen.throw(type, value, traceback)
_ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 

map = {<class 'concurrent.futures._base.TimeoutError'>: <class 'httpcore.ConnectTimeout'>, <class 'OSError'>: <class 'httpcore.ConnectError'>}

    @contextlib.contextmanager
    def map_exceptions(map: Dict[Type[Exception], Type[Exception]]) -> Iterator[None]:
        try:
            yield
        except Exception as exc:  # noqa: PIE786
            for from_exc, to_exc in map.items():
                if isinstance(exc, from_exc):
>                   raise to_exc(exc) from None
E                   httpcore.ConnectError: [SSL: WRONG_VERSION_NUMBER] wrong version number (_ssl.c:1091)

httpcore/_exceptions.py:12: ConnectError
@euri10
Copy link
Member

euri10 commented Feb 23, 2021

  • Not able to reproduce on my local macOS machine. CI uses Linux -> Can someone on Linux reproduce by running the test suite?

yes it does fail

  • It happens in test_connection_timeout_tcp, which does something hacky: try to connect via HTTPS to generate a ConnectTimeout. In CI we get a ConnectError instead. Probably related to the underlying openssl version?

I get this WRONG_VERSION_NUMBER indeed

❯ openssl version
OpenSSL 1.1.1d  10 Sep 2019
  ~/PycharmProjects/httpcore on   master ❯       

@JayH5
Copy link
Member

JayH5 commented Feb 23, 2021

I had a (failed) go at fixing this in #270. There definitely seem to be some differences in connection establishment in these edge cases between macOS and Linux.

IMO, the Linux error makes more sense and the tests shouldn't really be mis-using an SSL error to test this. However, I wasn't able to find a way to test connection timeouts on Linux easily.

@florimondmanca
Copy link
Member Author

Solved by #282.

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