sqlmapproject/sqlmap · error · H2Error

proxy closed connection during CONNECT

Error message

proxy closed connection during CONNECT

What it means

_connect_socket tunnel failure: the proxy closed the TCP connection while byte-reading the CONNECT response before the \r\n\r\n terminator arrived, so the tunnel could not be established (auth failure, unreachable origin, or proxy reset).

Solutions

  1. Check proxy availability and credentials
  2. Retry the connection through the proxy
Defensive patterns

Strategy: retry

When it happens

Trigger: Thrown at lib/request/http2.py:615 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of sqlmapproject/sqlmap@0a35b20e39 (2026-08-26). Data as JSON: /api/errors/150c98dec4432eb6. Report an issue: GitHub.

Appendix: source

Thrown at lib/request/http2.py:615

    raw = socket.create_connection((proxy_host, proxy_port), timeout=timeout)
    try:
        tunnel_host = _format_authority_host(host)
        authority = "%s:%d" % (tunnel_host, port)
        request = "CONNECT %s HTTP/1.1\r\nHost: %s\r\n" % (authority, authority)
        if proxy_cred:
            token = base64.b64encode(_as_bytes(proxy_cred)).decode("ascii")
            request += "Proxy-Authorization: Basic %s\r\n" % token
        request += "\r\n"
        raw.sendall(request.encode("latin-1"))

        # Read only through the CONNECT header terminator. A large recv() can consume
        # bytes from the tunneled TLS handshake that immediately follows the proxy
        # response, and those bytes cannot be pushed back before wrap_socket().
        response = bytearray()
        while not bytes(response).endswith(b"\r\n\r\n"):
            chunk = raw.recv(1)
            if not chunk:
                raise H2Error("proxy closed connection during CONNECT")
            response.extend(chunk)
            if len(response) > 65536:
                raise H2Error("oversized proxy CONNECT response")
        status_line = bytes(response).split(b"\r\n", 1)[0].decode("latin-1", "replace")
        fields = status_line.split(None, 2)
        code = int(fields[1]) if len(fields) >= 2 and fields[1].isdigit() else 0
        if not 200 <= code < 300:
            raise H2Error("proxy CONNECT failed: %s" % status_line)
        return raw
    except Exception:
        try:
            raw.close()
        except Exception:
            pass
        raise


def _make_ssl_context(verify, ssl_context):

View on GitHub (pinned to 0a35b20e39)