Skip to content

Broken master build: SSL_WRONG_VERSION_NUMBER #276

Closed

Description

@florimondmanca

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

Activity

  1. euri10 commented on Feb 23, 2021

    @euri10
    • 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 ❯       
    
  2. JayH5 commented on Feb 23, 2021

    @JayH5
    Contributor

    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.

  3. florimondmanca commented on Mar 23, 2021

    @florimondmanca
    ContributorAuthor

    Solved by #282.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions