javascript - node.js hapi.js socket memory leak on server AWS -


i have stack of servers on aws, , seems leaking memory. heapdump showing have ever increasing sockets in array, peer of sockets elbs sit in front of server instances.

the elbs ping health check every 6 seconds.

heapdump

how close these sockets if using hapi.js? how fix memory leak?

const config = require('./config'); const hapi = require('hapi'); const path = require('path'); const fs = require('fs');  server = new hapi.server({   debug: { request: ['error'] },   connections: {     routes: {       files: {         relativeto: path.join(__dirname, 'public')       }     }   } })  var connectiondict = {   port: config.port,   host: config.host}  server.connection(connectiondict); module.exports = server;  server.start(function () {       setimmediate(function(){         server.log([controller_name, "server-start"], 'server started at: ' + server.info.uri);       });     });  server.route({   method: 'get',   path: '/',   handler: function (request, reply) {     return reply('welcome api!\n').header("connection","close");   } });  setinterval(function (){  global.gc(); }, 60000); 

one interesting tidbit server has virtually no load - thing hitting servers elbs.

the sockets seen above repeats of same peer connection. i'm not sure why server not reusing existing socket , creating new ones.

the .header on reply seems doing nothing. sockets leak whether or not "connection:close" on return header.

unfortunately, global.gc() doesn't clean sockets.

edit not matters, using t2.micro instance.

simpler code, still leaking:

const hapi = require('hapi'); const fs = require('fs');  server = new hapi.server(); var connectiondict = {   port: 8443,   host: '0.0.0.0',   tls: {     key: fs.readfilesync('./cert/https/projectchange.pem'),     cert: fs.readfilesync('./cert/https/projectchange.cert'),     passphrase: 'somepassword'     }   } server.connection(connectiondict);  server.route({   method: 'get',   path: '/',   handler: function (request, reply) {     return reply('welcome change api!\n').header("connection","close");   } });  server.start(function (err) {   console.log('server started'); });  require('heapdump'); fs.readdirsync('.').map(function (filename) {   if (filename.match(/^heapdump-/)) {     console.log(filename);     fs.unlinksync(filename);   } }); setinterval(function heapdumper() {   process.kill(process.pid, 'sigusr2'); }, 60000); 


Comments

Popular posts from this blog

sql - VB.NET Operand type clash: date is incompatible with int error -

SVG stroke-linecap doesn't work for circles in Firefox? -

python - TypeError: Scalar value for argument 'color' is not numeric in openCV -