Skip to content

Commit 2ca539d

Browse files
committed
fix(socks5): preserve dispatch backpressure return value
Assited-by: openai:gpt-5.5 Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
1 parent 098b2d9 commit 2ca539d

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
@@ -177,7 +177,7 @@ class Socks5ProxyAgent extends DispatcherBase {
177177
/**
178178
* Dispatch a request through the SOCKS5 proxy
179179
*/
180-
async [kDispatch] (opts, handler) {
180+
[kDispatch] (opts, handler) {
181181
const { origin } = opts
182182

183183
debug('dispatching request to', origin, 'via SOCKS5')
@@ -234,8 +234,12 @@ class Socks5ProxyAgent extends DispatcherBase {
234234
return pool[kDispatch](opts, handler)
235235
} catch (err) {
236236
debug('dispatch error:', err)
237-
if (typeof handler.onError === 'function') {
237+
if (typeof handler.onResponseError === 'function') {
238+
handler.onResponseError(null, err)
239+
return false
240+
} else if (typeof handler.onError === 'function') {
238241
handler.onError(err)
242+
return false
239243
} else {
240244
throw err
241245
}

test/socks5-proxy-agent.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,28 @@ test('Socks5ProxyAgent - constructor validation', async (t) => {
3434
await p.completed
3535
})
3636

37+
test('Socks5ProxyAgent - dispatch returns boolean backpressure signal', async (t) => {
38+
const p = tspl(t, { plan: 1 })
39+
const proxyWrapper = new Socks5ProxyAgent('socks5://localhost:9999')
40+
41+
const ret = proxyWrapper.dispatch({
42+
origin: 'http://example.com',
43+
path: '/',
44+
method: 'GET'
45+
}, {
46+
onRequestStart () {},
47+
onResponseStart () {},
48+
onResponseData () {},
49+
onResponseEnd () {},
50+
onResponseError () {}
51+
})
52+
53+
p.equal(typeof ret, 'boolean')
54+
55+
await proxyWrapper.destroy()
56+
await p.completed
57+
})
58+
3759
test('Socks5ProxyAgent - basic HTTP connection', async (t) => {
3860
const p = tspl(t, { plan: 2 })
3961

0 commit comments

Comments
 (0)