softonic / axios-retry

Axios plugin that intercepts failed requests and retries them whenever possible
Other
1.9k stars 167 forks source link

Abort during retry causes uncaught exception #278

Closed finbargp closed 5 months ago

finbargp commented 5 months ago

We're seeing an issue where an abort during a retry causes an uncaught exception which is bringing our server down. We believe this may have been introduced by https://github.com/softonic/axios-retry/pull/273 as it has only started happening since then.

An example test to reproduce this (based on existing should clear timeout if started test) is below:

This is currently failing with an uncaught exception.

Can someone please have a look?

Please let me know if you need any further information.

        it('should cancel old requests', (done) => {
          const client = axios.create();
          setupResponses(client, [
            () => nock('http://example.com').get('/test').delay(100).reply(429),
            () => nock('http://example.com').get('/test').delay(100).reply(429),
            () => nock('http://example.com').get('/test').delay(100).reply(429),
          ]);
          axiosRetry(client, {
            retries: 2,
            retryCondition: () => true,
            retryDelay: () => 0,
          });
          const abortController = new AbortController();
          client
            .get('http://example.com/test', { signal: abortController.signal })
            .then(
              () => done.fail(),
              (error) => {
                expect(error).toBeInstanceOf(CanceledError);
                expect(new Date().getTime() - timeStart).toBeLessThan(300);
                done();
              },
            )
            .catch(done.fail);
          setTimeout(() => abortController.abort(), 250);
          const timeStart = new Date().getTime();
        });
mindhells commented 5 months ago

@michal-billtech could you have a look into this?

michal-billtech commented 5 months ago

Sure!

michal-billtech commented 5 months ago

Thanks for reporting this. The issue seems to be caused by abort listener not being cleared. PR on the way