Skip to content
This repository has been archived by the owner on Sep 25, 2020. It is now read-only.

KeepAliveAgent leaks memory when run under node 6 #23

Open
ksheedlo opened this issue Feb 20, 2017 · 3 comments
Open

KeepAliveAgent leaks memory when run under node 6 #23

ksheedlo opened this issue Feb 20, 2017 · 3 comments

Comments

@ksheedlo
Copy link

cc @Raynos

The following test program exhibits a memory leak when run under node 6.

'use strict';

require('heapdump');
var Pool = require('lb_pool').Pool;
var http = require('http');

process.on('warning', warning => {
  console.error(warning.stack);
});

var httpClient = new Pool(http, ['localhost:3001'], {keep_alive: true});

function makeRequest() {
  httpClient.get('/foof', function handleGetCall(err, res, body) {
    if (err) {
      console.log('ERROR', err);
    } else {
      console.log('GET /foof ok');
    }

    setTimeout(makeRequest, 1000);
  });
}

makeRequest();

Here is the output when running on my laptop (note: I run a dummy server on localhost:3001 that just returns 200)

GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
GET /foof ok
(node:27128) Warning: Possible EventEmitter memory leak detected. 11 timeout listeners added. Use emitter.setMaxListeners() to increase limit
Warning: Possible EventEmitter memory leak detected. 11 timeout listeners added. Use emitter.setMaxListeners() to increase limit
    at _addListener (events.js:259:19)
    at Socket.addListener (events.js:275:10)
    at Socket.Readable.on (_stream_readable.js:687:35)
    at Socket.once (events.js:301:8)
    at tickOnSocket (_http_client.js:566:12)
    at onSocketNT (_http_client.js:580:5)
    at _combinedTickCallback (internal/process/next_tick.js:74:11)
    at process._tickCallback (internal/process/next_tick.js:98:9)

Additionally, heapdump analysis shows a memory leak. Here are the heapdumps I collected: heapdumps.zip. Load them in the following order to see the leak.

  1. heapdump-48854102.4747.heapsnapshot
  2. heapdump-49041021.610678.heapsnapshot
  3. heapdump-49196662.155354.heapsnapshot

If I instead pass {keep_alive: false} to lb_pool.Pool, the warning and leaking heap objects go away. So, I'm reasonably confident the leak is in the KeepAliveAgent.

@ksheedlo
Copy link
Author

possibly a duplicate of nodejs/node#9268

@lxe
Copy link

lxe commented Mar 10, 2017

From nodejs/node#9268 (comment):

This is merged in 6.10

I am indeed unable to reproduce this on node 6.10.0

@davidkearns
Copy link

There is a followup issue at nodejs/node#9668 that also seems related.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants