Skip to content

httpx hangs indefinitely when websocket is encountered #2517

Closed

Description

@meme-lord

httpx version: v1.9.0

Current Behavior:

httpx -u http://cediplast.myqnapcloud.com:8085 -stats -v

This command runs indefinitely. Timeouts are not respected

Expected Behavior:

Httpx should end the connection at some point and report that the server is live

Anything else:

Server response from curl:

> GET / HTTP/1.1
> Host: cediplast.myqnapcloud.com:8085
> User-Agent: curl/8.20.0
> Accept: */*
>
* Request completely sent off
< HTTP/1.1 101 Switching Protocols
< Server: SBS
< Upgrade: websocket
< Connection: Upgrade
< Sec-WebSocket-Accept: 5eDZZbOR6sddfLJc+jA8+DMLXS8=
< Sec-WebSocket-Version: 13

Activity

  1. added
    Type: Bug
    on Jun 18, 2026
  2. sophymarine commented on Jun 18, 2026

    @sophymarine

    Your curl output shows a classic upgrade flow. HTTP/1.1 101 Switching Protocols means the server accepted a WebSocket upgrade and will hold the TCP connection open instead of returning a normal HTTP body.

    That tends to confuse tools built for request–response probing. httpx reads the Upgrade: websocket header, sees the 101, then keeps waiting on the stream because the connection never closes. No body arrives. The timeout path never fires.

    I hit the same behaviour with a WS endpoint a while back. The simple fix was treating 101 as a finished probe. Read headers, record the status, then close immediately. In Go that usually means returning as soon as resp.StatusCode == 101 instead of attempting io.ReadAll on the body. That header-only branch should stop the hang.

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

Metadata

Metadata

Assignees

Labels

Type: Bug

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions