Skip to content

fix: pass timeout to SOCKS5 handshake reads to prevent infinite blocking#1092

Open
muhamedfazalps wants to merge 1 commit into
encode:masterfrom
muhamedfazalps:fix/socks5-timeout
Open

fix: pass timeout to SOCKS5 handshake reads to prevent infinite blocking#1092
muhamedfazalps wants to merge 1 commit into
encode:masterfrom
muhamedfazalps:fix/socks5-timeout

Conversation

@muhamedfazalps

Copy link
Copy Markdown

_init_socks5_connection calls stream.read() three times without passing a timeout argument. SyncStream.read() calls settimeout(None) which puts the socket into infinite blocking mode, overriding any timeout set during socket creation. This causes requests to hang indefinitely when using a SOCKS5 proxy that stalls during the handshake.

Fixes #1089

import httpx

# Before: hangs forever if SOCKS5 proxy stalls during handshake
# After: timeout is respected, raises ReadTimeout
proxy = httpx.Proxy("socks5://127.0.0.1:9150")
with httpx.Client(proxy=proxy, timeout=5.0) as client:
    client.get("http://example.com")  # now times out correctly

_init_socks5_connection calls stream.read() three times without passing
a timeout argument. SyncStream.read() calls settimeout(None) which puts
the socket into infinite blocking mode, overriding any timeout set during
socket creation. This causes requests to hang indefinitely when using a
SOCKS5 proxy that stalls during the handshake.

Fixes encode#1089
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

Successfully merging this pull request may close these issues.

_init_socks5_connection ignores timeout — SyncStream.read() puts socket into infinite blocking mode

1 participant