From 7752093f257e7eddb7b7492ba575b1575439e533 Mon Sep 17 00:00:00 2001 From: "Kamat, Trivikram" <16024985+trivikr@users.noreply.github.com> Date: Fri, 1 May 2026 19:49:08 -0700 Subject: [PATCH] fix(socks5): preserve dispatch backpressure return value Assited-by: openai:gpt-5.5 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> --- lib/dispatcher/socks5-proxy-agent.js | 8 ++++++-- test/socks5-proxy-agent.js | 22 ++++++++++++++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) diff --git a/lib/dispatcher/socks5-proxy-agent.js b/lib/dispatcher/socks5-proxy-agent.js index db60a8a025f..3cc5b19f0be 100644 --- a/lib/dispatcher/socks5-proxy-agent.js +++ b/lib/dispatcher/socks5-proxy-agent.js @@ -173,7 +173,7 @@ class Socks5ProxyAgent extends DispatcherBase { /** * Dispatch a request through the SOCKS5 proxy */ - async [kDispatch] (opts, handler) { + [kDispatch] (opts, handler) { const { origin } = opts debug('dispatching request to', origin, 'via SOCKS5') @@ -230,8 +230,12 @@ class Socks5ProxyAgent extends DispatcherBase { return pool[kDispatch](opts, handler) } catch (err) { debug('dispatch error:', err) - if (typeof handler.onError === 'function') { + if (typeof handler.onResponseError === 'function') { + handler.onResponseError(null, err) + return false + } else if (typeof handler.onError === 'function') { handler.onError(err) + return false } else { throw err } diff --git a/test/socks5-proxy-agent.js b/test/socks5-proxy-agent.js index db36b40df05..d69f2906792 100644 --- a/test/socks5-proxy-agent.js +++ b/test/socks5-proxy-agent.js @@ -84,6 +84,28 @@ test('Socks5ProxyAgent - uses custom connector for proxy connection', async (t) await p.completed }) +test('Socks5ProxyAgent - dispatch returns boolean backpressure signal', async (t) => { + const p = tspl(t, { plan: 1 }) + const proxyWrapper = new Socks5ProxyAgent('socks5://localhost:9999') + + const ret = proxyWrapper.dispatch({ + origin: 'http://example.com', + path: '/', + method: 'GET' + }, { + onRequestStart () {}, + onResponseStart () {}, + onResponseData () {}, + onResponseEnd () {}, + onResponseError () {} + }) + + p.equal(typeof ret, 'boolean') + + await proxyWrapper.destroy() + await p.completed +}) + test('Socks5ProxyAgent - basic HTTP connection', async (t) => { const p = tspl(t, { plan: 2 })