Skip to content

fix(net): expose the SOCKS5 proxy-connect failure stage - #42

Merged
Antruly merged 2 commits into
masterfrom
fix/socks5-proxy-stage
Oct 20, 2026
Merged

Antruly merged 2 commits into
masterfrom
fix/socks5-proxy-stage

Conversation

@Antruly

@Antruly Antruly commented Oct 20, 2026

Copy link
Copy Markdown
Owner

Problem

socks5_last_error() reports connection refused in two very different cases:

  • the proxy TCP connect (or its DNS lookup / connect timeout) fails — the proxy was never reached;
  • the proxy answers CONNECT with REP=0x05 — the proxy is reachable and the target refused.

Callers that classify failures (for example uvscope's proxy_unreachable vs target_rejected) currently cannot tell them apart from the public API.

Change

  • Track the failure stage in uvcpp_tcp_client: set a flag on proxy connect / DNS / connect-timeout failures, reset it when a new SOCKS5 attempt starts.
  • Export socks5_proxy_connect_failed() (read-only) and forward it from uvcpp_http_client.
  • No behavior change for successful connects or for the existing error codes/messages.
  • Add a functional test covering: dead proxy, proxy-rejected target, wrong password, and the successful path.

Verification

$ cmake --build build --target test_socks5_client_func
$ ./build/tests/functional/test_socks5_client_func
[socks5] connect_no_auth ok
[socks5] connect_domain_target ok
[socks5] connect_auth ok
[socks5] bind ok
[socks5] udp_associate ok
[socks5] proxy_failure_stage ok
[socks5] ALL PASSED

Also exercised by uvscope's smoke suite on v1.8.0 + this patch: dead proxy → proxy_unreachable, proxy REP=0x05 → target_rejected, wrong credentials → auth_failed.

socks5_last_error() reports "connection refused" both when the proxy
TCP connect fails and when the proxy rejects CONNECT with REP=0x05.
Callers that classify errors cannot tell "proxy unreachable" from
"target rejected" without joining the two pieces of information.

Track the stage in uvcpp_tcp_client: set a flag when the proxy TCP
connect, its DNS resolution, or the connect timeout fails; clear it when
a new SOCKS5 attempt starts; expose socks5_proxy_connect_failed().
Forward the accessor from uvcpp_http_client.

Add a functional test covering a dead proxy, a proxy-rejected target, a
wrong password and the successful path.
The new public/private members shift uvcpp_tcp_client and
uvcpp_http_client line numbers; move the documented references by the
same offsets and refresh doc_line_refs.lock.
@Antruly
Antruly merged commit 48c65bf into master Oct 20, 2026
43 checks passed
@Antruly
Antruly deleted the fix/socks5-proxy-stage branch October 20, 2026 08:02
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.

1 participant