A simple server (proxy), getting MEDIUM traffic, is oddly leaking.
The code is simply:
var net = require('net');
var dgram = require('dgram');
var server3 = net.createServer();
var udp_sv3 = dgram.createSocket('udp4');
var load_balancer = null;
udp_sv3.bind(9038);
udp_sv3.on('message', udpHandler);
server3.listen(2103);
server3.on('connection', connHandler);
function udpHandler(msg, sender) {
if (!load_balancer && sender.size === 4) load_balancer = sender;
if (load_balancer.address === sender.address) {
this.send(msg, 0, msg.length, 9038, 'xxxxxx');
} else {
this.send(msg, 0, msg.length, load_balancer.port, load_balancer.address);
}
msg = null;
}
function connHandler(client) {
var port = this.address().port;
var gate = net.connect({ host: 'xxxxxx', port: port });
gate.pipe(client).pipe(gate);
client.setNoDelay();
gate.setNoDelay();
client.on('error', function (error) {});
gate.on('error', function (error) {});
}
And that is it, but monitoring with pm2 is currently showing:
│ App name │ id │ mode │ PID │ status │ restarted │ uptime │ memory │
├──────────┼────┼──────┼───────┼────────┼───────────┼────────┼──────────────┤
│ index │ 0 │ fork │ 16043 │ online │ 0 │ 2h │ 977.125 MB │
And the number of sockets currently connected is 267
. Which is currently low because usually it would reach beyond 1000
. But the point is its still leaking.
What is wrong?
- 5 minutes after posting above and the memory is at
987.281MB
with261
sockets connected. - 3 minutes later:
993.676MB
with260
sockets connected. - 10 minutes later:
1.060GB
with248
sockets connected.
Is node not gc'ing?