Skip to content

Commit e2bc508

Browse files
authored
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>
1 parent 593530f commit e2bc508

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
@@ -173,7 +173,7 @@ class Socks5ProxyAgent extends DispatcherBase {
173173
/**
174174
* Dispatch a request through the SOCKS5 proxy
175175
*/
176-
async [kDispatch] (opts, handler) {
176+
[kDispatch] (opts, handler) {
177177
const { origin } = opts
178178

179179
debug('dispatching request to', origin, 'via SOCKS5')
@@ -230,8 +230,12 @@ class Socks5ProxyAgent extends DispatcherBase {
230230
return pool[kDispatch](opts, handler)
231231
} catch (err) {
232232
debug('dispatch error:', err)
233-
if (typeof handler.onError === 'function') {
233+
if (typeof handler.onResponseError === 'function') {
234+
handler.onResponseError(null, err)
235+
return false
236+
} else if (typeof handler.onError === 'function') {
234237
handler.onError(err)
238+
return false
235239
} else {
236240
throw err
237241
}

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)