Fix SOCKS proxy hangs and enable third-party resource loading#1
Open
Pebl3 wants to merge 2 commits intosenderend:masterfrom
Open
Fix SOCKS proxy hangs and enable third-party resource loading#1Pebl3 wants to merge 2 commits intosenderend:masterfrom
Pebl3 wants to merge 2 commits intosenderend:masterfrom
Conversation
Refactor SOCKS server to handle DNS requests directly and improve error handling for connections without relays.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Disclaimer... all code is completely AI generated, but I have verified that the patch works and removed bloat.
Summary
Two bugs made the SOCKS proxy unusable for real browser traffic against relayed targets: non-relay hosts (CDNs, fonts) got rejected outright, and a single slow relay response could deadlock the entire proxy. This PR fixes both.
Problems
1. Third-party resources rejected. The SOCKS handler required every connection to have an active relay session, so any page pulling in CDN/font assets failed:
2. Whole-proxy deadlock after a few seconds. The relay socket used
settimeout(None), and everyrecv()path (transferResponsebody read,transferChunked) was unguarded. One slow/hung response from the target heldsocketLockforever. Every subsequent browser connection blocked on lock acquisition and the browser spun on "infinite loading."Changes
lib/relay/servers/socksserver.py— direct TCP passthrough for non-relay trafficCONNECTION_REFUSEDgate for unknown hosts.select-based bidirectional pipe in the "no relay handler" branch, matching the pattern already used for DNS (port 53).lib/relay/servers/socksplugins/http.py— bounded relay I/O_sendViaRelay()helper wrapping the lock/send/recv sequence:relaySocketcovers everyrecv()intransferResponseandtransferChunked.isConnectionAlive()cleanly instead of reading misaligned response bytes.with socketLock:blocks in_processRequestWithProbeinto single_sendViaRelay()calls.Behavior
CONNECTION_REFUSEDTrade-offs
A true target-side hang now ends the NTLM session (relay socket closed). Re-capture is needed — acceptable since the alternative is a dead proxy.