No way to catch EADDRINUSE
- Dominant language
- JavaScript
- Stars
- 7.9k
- Forks
- 1.2k
- PR merge metrics
- No merged PRs in 30d
Description
```javascript
const AnyProxy = require("anyproxy");
function startProxy() {
const options = {
port: 8001,
//rule: require("myRuleModule"),
webInterface: {
enable: true,
webPort: 8002
},
throttle: 10000,
forceProxyHttps: false,
wsIntercept: false,
silent: false
};
const proxyServer = new AnyProxy.ProxyServer(options);
proxyServer.on("ready", () => {
console.log("PROXY READY");
});
proxyServer.on("error", e => {
console.log("PROXY ERROR");
/* */
});
proxyServer.start();
}
//starting proxy twice on purpose
startProxy();
startProxy();
```
#### Which platform are you running AnyProxy
Mac
#### The version of the AnyProxy
4.0.12
#### Your expected behavior of AnyProxy
should emit an 'error' if port is in use
#### The actual behavior of AnyProxy
Any proxy emits a 'ready' and later logs that the port is in use. No way to catch error.
#### The log of the error
[AnyProxy Log][2018-11-04 01:33:44]: throttle :10000kb/s
[AnyProxy Log][2018-11-04 01:33:44]: throttle :10000kb/s
[AnyProxy ERROR][2018-11-04 01:33:44]: websocket error, Error: listen EADDRINUSE :::8002
[AnyProxy Log][2018-11-04 01:33:44]: Http proxy started on port 8001
[AnyProxy Log][2018-11-04 01:33:44]: web interface started on port 8002
PROXY READY
[AnyProxy Log][2018-11-04 01:33:44]: Http proxy started on port 8001
[AnyProxy Log][2018-11-04 01:33:44]: web interface started on port 8002
PROXY READY
[AnyProxy ERROR][2018-11-04 01:33:44]: error in websocket proxy: listen EADDRINUSE :::8001,
Error: listen EADDRINUSE :::8001
at Server.setupListenHandle [as _listen2] (net.js:1286:14)
at listenInCluster (net.js:1334:12)
at Server.listen (net.js:1421:7)
at async.series.tipText (/Users/me/Desktop/anyproxy-test/node_modules/anyproxy/proxy.js:205:32)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:607:21
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:246:17
at iterate (/Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:146:13)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:157:25
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:248:21
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:612:34
at async.series.tipText (/Users/me/Desktop/anyproxy-test/node_modules/anyproxy/proxy.js:200:11)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:607:21
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:246:17
at iterate (/Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:146:13)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:157:25
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:248:21
error happened in proxy websocket: { Error: listen EADDRINUSE :::8001
at Server.setupListenHandle [as _listen2] (net.js:1286:14)
at listenInCluster (net.js:1334:12)
at Server.listen (net.js:1421:7)
at async.series.tipText (/Users/me/Desktop/anyproxy-test/node_modules/anyproxy/proxy.js:205:32)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:607:21
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:246:17
at iterate (/Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:146:13)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:157:25
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:248:21
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:612:34
at async.series.tipText (/Users/me/Desktop/anyproxy-test/node_modules/anyproxy/proxy.js:200:11)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:607:21
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:246:17
at iterate (/Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:146:13)
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:157:25
at /Users/me/Desktop/anyproxy-test/node_modules/async/lib/async.js:248:21
errno: 'EADDRINUSE',
code: 'EADDRINUSE',
syscall: 'listen',
address: '::',
port: 8001 }
Contributor guide
No contributing guide indexed for this repository
Research direction
Reproduce the issue by starting two AnyProxy.ProxyServer instances with the example options. Read proxy.js around lines 200-205, where the listen failure is reported, and trace how it reaches the server events. Done means an EADDRINUSE failure is exposed through the documented error-handling path instead of producing a misleading ready event.
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
- Clearly specified
- Newbie friendliness
- 35/100