Skip to content

CancelToken causes memory leak if re-used for multiple requests #3001

@barryspearce

Description

@barryspearce

Obtaining a cancel token (as per the Axios documentation on github) and re-using it across many requests results in a major memory leak as the payload for each request is not freed.

I am transferring large files - from 3 GB to 100GB using a chunked protocol and 20MB requests. The memory fills and remains until the cancel token reference is removed. Using the same code but not setting the cancel token in the config resolved the issue.

Creating a cancel token for each and every single request individually and removing the reference to the cancel token achieves the expected behaviour and frees the request payload memory.

Simple use of chrome dev tools and memory profile shows the cancel token as holding the memory, also reflect in process stats using top.

This is not using the global axios but an instance.

Previously reported in #1118 but it is unclear if this was properly resolved.

Axios 0.19.2
OS Linux
Browsers: Firefox 76.0, Opera 68.0.3618.63, Chromium 81.0.4044.129

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