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

KeepAliveAgent leaks memory when run under node 6 #23

@ksheedlo

Description

@ksheedlo

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions