EPIPE和ECONNRESET错误处理
- Dominant language
- JavaScript
- Stars
- 7.9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
EPIPE和ECONNRESET错误处理
在HTTPS模式下,需要添加socket.on('error')处理,否则会抛出EPIPE和ECONNRESET未捕获异常,导致程序异常退出,并且pm2池重启后会导致端口占用无法重启成功。
暂时解决办法
proxy.js
handleExistConnections(socket) {
const self = this;
self.socketIndex ++;
const key = `socketIndex_${self.socketIndex}`;
self.socketPool[key] = socket;
// if the socket is closed already, removed it from pool
socket.on('close', () => {
delete self.socketPool[key];
});
}
#### Which platform are you running AnyProxy
Linux
#### The version of the AnyProxy
4.0
#### Your expected behavior of AnyProxy
#### The actual behavior of AnyProxy
#### The log of the error
error happened in proxy websocket: { Error: listen EADDRINUSE :::8001
at Server.setupListenHandle [as _listen2] (net.js:1336:14)
at listenInCluster (net.js:1384:12)
at Server.listen (net.js:1471:7)
at async.series.tipText (/usr/local/node/lib/node_modules/anyproxy/proxy.js:205:32)
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:607:21
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:246:17
at iterate (/usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:146:13)
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:157:25
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:248:21
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:612:34
at async.series.tipText (/usr/local/node/lib/node_modules/anyproxy/proxy.js:200:11)
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:607:21
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:246:17
at iterate (/usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:146:13)
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:157:25
at /usr/local/node/lib/node_modules/anyproxy/node_modules/async/lib/async.js:248:21
errno: 'EADDRINUSE',
code: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8001 }
Error: write EPIPE
at WriteWrap.afterWrite [as oncomplete] (net.js:836:14)
[AnyProxy ERROR][2018-08-11 11:57:43]: got an uncaught exception, is there anything goes wrong in your rule file ?
Contributor guide
No contributing guide indexed for this repository
Research direction
Start in proxy.js at handleExistConnections(socket), using the reported EPIPE and ECONNRESET stack traces to trace the HTTPS socket lifecycle. Confirm that socket errors no longer become uncaught exceptions and that the proxy can restart without leaving port 8001 occupied.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- backend, networking
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 48/100