Axios hanging on retry

564 views Asked by At

axios version 0.19.2 axios-retry version 3.1.9 also using FormData 2.5.1 using an express server

I'm trying to resend data on a failed checksum match. I'm sending a 406 from the express server. Axios appears to attempt a retry but then it hangs. If I stop the express server, the program continues with its retries. If I restart the server, axios appears to hang again.

    axiosRetry(axios, {
      retries: 10,
      retryDelay: (retryCount) => {
        console.log(`retry attempt ${retryCount}`);
        return retryCount * 1000;
      },
      retryCondition: (_err) => true
    })

   axios.post(
      url,
      newForm,
      {
        headers: {
          ...headers,
        }
      }
    )
    .then((res) => {
      Log(res);
      if (res.status === 200) {
        // do some stuff
      }
    })
    .catch((err) => {
      Log(err)
      if (err.response) {
        if (err.response.status === 406) {
          console.log("got a 406")
        }
      }
    });

I am misunderstanding something about axios/axiosRetry and FormData. I had some code yesterday (gone now) that if the post request were sent while the server was down, it would retry and eventually make a "successful" post but on the express side, the request seemed to appear without a body. I was able to get that far by skipping the formData and posting the filestream itself. I don't remember how I handled the headers.

I'm not really sure where to go from here. Any help is appreciated.

EDIT: So the problem seems to have been a combination of using formData and the headers. Here is the modified request that works for this instance.

axios({
  method: 'post',
  url:  url,
  headers: {formHeaders},
  data: fs.createReadStream({`${file}`})
});
0

There are 0 answers