Apply the connect timeout to the SOCKS5 handshake#1097
Open
wwmanidumaneesha wants to merge 1 commit into
Open
Conversation
The connect timeout was resolved and passed to `connect_tcp()`, but then omitted from the SOCKS5 handshake that follows. `_init_socks5_connection()` took no timeout at all, so its reads and writes were unbounded. A proxy that accepts the TCP connection and then stops responding therefore blocked forever, whatever timeouts had been configured. Closes encode#1015, closes encode#1089.
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.
Apply the connect timeout to the SOCKS5 handshake
Closes #1015. Closes #1089.
The problem
The connect timeout is resolved and passed to
connect_tcp(), but then dropped for the SOCKS5 handshake that immediately follows:_init_socks5_connection()took notimeoutparameter at all, so all three of itsstream.read(max_bytes=4096)calls were unbounded.A proxy that completes the TCP handshake and then stops responding therefore blocks forever, whatever timeouts were configured.
The fix
Thread the connect timeout through the handshake, so it covers the reads and writes that talk to the proxy as well as the connection to it.
Tests
test_socks5_connect_timeout_applies_to_handshakerecords the timeout applied to each read and asserts that the two handshake reads — the auth method reply and the connect reply — are both bounded by the configured connect timeout.On
masterit fails with[None, None] == [5.0, 5.0].