softonic/axios-retry

Memory leak when using axios-retry

Opened this issue · 4 comments

It seems anytime I use axios with axios-retry enabled, the response returned by the request stays in memory and never gets garbage collected. If I simply comment out the axiosRetry block of code the response does not stay in memory and is garbage collected properly.

I am using axios@0.27.2 and axios-retry@3.3.1 running in NodeJS v18.9, there's nothing special about my implementation:

axiosRetry(axios, {
    retries: 5,
    retryDelay: () => {
        return 5000;
    }
});

const requestFields = {
    method: 'GET',
    url: 'XXXXXXXXXX'
};

axios
    .request<T>(requestFields)
    .then((response) => resolve(response.data))
    .catch((error: AxiosError) => {
        console.log(error);
        resolve();
    });

I also am having this issue with it. Brought down some production code and after removing the library it no longer has any issues. Working with Node 16 and axios 0.27.2

I had the same problem in the 3.4.0 version, therefore I changed axios-retry to async.retry. The issue has been resolved. I am hopeful that the axios-retry team will be able to resolve this issue soon. https://caolan.github.io/async/v3/docs.html#retry

Facing same issue

Maybe just a thought but how are you using the instance of the axios?

My thought was that If you are using the same instance over and over as a singleton, the created and registered interceptors still can be bounded to that instance, making it unable for the GC to collect the resources properly.

The axiosRetry call retruns you the ids of the interceptors, did you try ejecting them once the work is done?

const { requestInterceptorId, responseInterceptorId } = axiosRetry(axios, {
    retries: 5,
    retryDelay: () => {
        return 5000;
    }
});


axios.interceptors.request.eject(requestInterceptorId);
axios.interceptors.response.eject(responseInterceptorId);