Skip to content

Memory leak when body is not used #83

@georgecrawford

Description

@georgecrawford

I wanted to test a URL for validity; verifying that it returns a 200 response.

Using this code:

const fetch = require('node-fetch');

module.exports = (url) => fetch(url)
    .then(res => res.status === 200 && url);

...I found it caused a memory leak. Node that I"m not calling .body() or .json(). Profiling the memory usage over time, I was suspicious that lots of stream objects were being keep in memory. I speculatively added {method: 'HEAD'} to the options (which is of course the right thing to do in this case anyway), which fixed the memory leak.

Is this a bug in node-fetch? Should memory be freed whether or not the body of the response is ever used? If it's not a bug, I wonder if the documentation should make it clear that responses with a body must be cleared in some way to free memory?

Thanks for a great library!

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