Skip to content

Commit fcd642f

Browse files
trivikrmcollina
authored andcommitted
fix(socks5): preserve dispatch backpressure return value (#5166)
Assited-by: openai:gpt-5.5 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com> (cherry picked from commit e2bc508)
1 parent bc98c97 commit fcd642f

2 files changed

Lines changed: 28 additions & 2 deletions

File tree

lib/dispatcher/socks5-proxy-agent.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ class Socks5ProxyAgent extends DispatcherBase {
167167
/**
168168
* Dispatch a request through the SOCKS5 proxy
169169
*/
170-
async [kDispatch] (opts, handler) {
170+
[kDispatch] (opts, handler) {
171171
const { origin } = opts
172172

173173
debug('dispatching request to', origin, 'via SOCKS5')
@@ -224,8 +224,12 @@ class Socks5ProxyAgent extends DispatcherBase {
224224
return pool[kDispatch](opts, handler)
225225
} catch (err) {
226226
debug('dispatch error:', err)
227-
if (typeof handler.onError === 'function') {
227+
if (typeof handler.onResponseError === 'function') {
228+
handler.onResponseError(null, err)
229+
return false
230+
} else if (typeof handler.onError === 'function') {
228231
handler.onError(err)
232+
return false
229233
} else {
230234
throw err
231235
}

test/socks5-proxy-agent.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,28 @@ test('Socks5ProxyAgent - uses custom connector for proxy connection', async (t)
8484
await p.completed
8585
})
8686

87+
test('Socks5ProxyAgent - dispatch returns boolean backpressure signal', async (t) => {
88+
const p = tspl(t, { plan: 1 })
89+
const proxyWrapper = new Socks5ProxyAgent('socks5://localhost:9999')
90+
91+
const ret = proxyWrapper.dispatch({
92+
origin: 'http://example.com',
93+
path: '/',
94+
method: 'GET'
95+
}, {
96+
onRequestStart () {},
97+
onResponseStart () {},
98+
onResponseData () {},
99+
onResponseEnd () {},
100+
onResponseError () {}
101+
})
102+
103+
p.equal(typeof ret, 'boolean')
104+
105+
await proxyWrapper.destroy()
106+
await p.completed
107+
})
108+
87109
test('Socks5ProxyAgent - basic HTTP connection', async (t) => {
88110
const p = tspl(t, { plan: 2 })
89111

0 commit comments

Comments
 (0)