Skip to content

Commit 362f407

Browse files
committed
Ignore prematurely closed sockets
1 parent 97c2a4e commit 362f407

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

lib/proxy-server.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,13 @@ module.exports = class ProxyServer extends Nanoresource {
3030

3131
this[kServer].on('request', onRequest(proxy.web.bind(proxy)))
3232
this[kServer].on('upgrade', onRequest(proxy.ws.bind(proxy)))
33+
this[kServer].on('error', ignorePrematureClose)
3334

3435
enableDestroy(this[kServer])
36+
3537
proxy.on('proxyReq', onProxyReq)
38+
proxy.on('error', ignorePrematureClose)
39+
proxy.onError = ignorePrematureClose
3640

3741
function onProxyReq (proxyReq, req, res, options) {
3842
proxyReq.setHeader('x-airtap-context-id', cid)
@@ -85,6 +89,14 @@ module.exports = class ProxyServer extends Nanoresource {
8589
}
8690
}
8791

92+
function ignorePrematureClose (err) {
93+
if (err.code === 'ECONNRESET') {
94+
debug('Socket closed prematurely')
95+
} else {
96+
throw err
97+
}
98+
}
99+
88100
function maybeLookup (hostname, opts, callback) {
89101
if (hostname === ip) {
90102
process.nextTick(callback, null, ip)

0 commit comments

Comments
 (0)