pFad - Phone/Frame/Anonymizer/Declutterfier! Saves Data!


--- a PPN by Garber Painting Akron. With Image Size Reduction included!

URL: http://github.com/encode/httpcore/pull/1055

eet" href="https://github.githubassets.com/assets/actions-26401580c700f528.css" /> Fix: Pass timeout to SOCKS5 handshake to prevent hanging by drshvik · Pull Request #1055 · encode/httpcore · GitHub
Skip to content

Fix: Pass timeout to SOCKS5 handshake to prevent hanging#1055

Open
drshvik wants to merge 3 commits intoencode:masterfrom
drshvik:fix/socks5-handshake-timeout
Open

Fix: Pass timeout to SOCKS5 handshake to prevent hanging#1055
drshvik wants to merge 3 commits intoencode:masterfrom
drshvik:fix/socks5-handshake-timeout

Conversation

@drshvik
Copy link
Copy Markdown

@drshvik drshvik commented Jan 30, 2026

Summary

This PR fixes a critical issue where SOCKSProxy ignores the configured connect timeout during the SOCKS5 handshake.

Previously, the timeout was used to establish the initial TCP connection, but it was not passed to the _init_socks5_connection function. As a result, if a proxy server accepted the TCP connection but failed to send data (e.g., a "blackhole" server), the client would hang indefinitely (or until the OS socket timeout) regardless of the user's configured timeout.

The Fix

  • Updated _init_socks5_connection in both _sync/socks_proxy.py and _async/socks_proxy.py to accept a timeout argument.
  • Passed this timeout explicitly to all stream.read() and stream.write() calls during the authentication and connection negotiation phases.
  • Updated Socks5Connection.handle_request (and its async counterpart) to extract the connect timeout from request.extensions and pass it to the initialization function.

Reproduction

I verified this fix using a local reproduction script that simulates a hanging SOCKS5 proxy.

  • Before: The client hung for >20s (ignoring the 2s timeout).
  • After: The client correctly raises TimeoutException after 2s.

Checklist

  • I understand that this PR may be closed in case there was no previous discussion.
  • I've verified the fix with reproduction scripts (see above).
  • I've updated the documentation accordingly. (Not applicable for this bug fix)

@drshvik
Copy link
Copy Markdown
Author

drshvik commented Jan 30, 2026

All checks are passing and I'm happy to make any changes if needed. Thanks!

@drshvik
Copy link
Copy Markdown
Author

drshvik commented Jan 30, 2026

I noticed this appears to address the same issue as #1017. I've submitted this fresh PR because I verified the bug still exists on the current main branch, and I ensured this version passes all current linting and test checks. Happy to supersede the older PR if that one is inactive.

@alistard
Copy link
Copy Markdown

alistard commented Mar 8, 2026

Great, this solved my problem. The interesting thing is why it wasn't merged. @lovelydinosaur @florimondmanca

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.

2 participants

pFad - Phonifier reborn

Pfad - The Proxy pFad © 2024 Your Company Name. All rights reserved.





Check this box to remove all script contents from the fetched content.



Check this box to remove all images from the fetched content.


Check this box to remove all CSS styles from the fetched content.


Check this box to keep images inefficiently compressed and original size.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy