Skip to content

Mem leak when keepalive is used #1446

@zdm

Description

@zdm

node-fetch: 3.1.0
nodejs: 17.3.0

Memory working set is grows and not freed:

import fetch from "node-fetch";
import http from "http";

const agent = new http.Agent( {
    "keepAlive": true,
    // keepAliveMsecs: 5000,
} );

var i = 0;

while ( 1 ) {

    const res = await fetch("http://example.com", { agent });
    await res.text();

    console.log( ++i, res.status );
}

For pure node http everything is ok:

import http from "http";

const agent = new http.Agent( {
    "keepAlive": true,
    // keepAliveMsecs: 5000,
} );

var i = 0;

while ( 1 ) {
    const res = await new Promise( resolve => {
        http.get( "http://example.com/", { agent }, res => {
            res.on( "data", chunk => {} );

            res.on( "end", () => {
                resolve( { "status": res.statusCode } );
            } );
        } );
    } );

    console.log( ++i, res.status );
}

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions