Move FormData instantiation inside makeRequest retry #274
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I have been troubleshooting a perplexing issue when updating the happo.io package at Airbnb. It seems that on this new version when a request fails and is retried it ends up erroring out with a socket hang up error after 60 seconds.
After some investigation, this error seems to be exactly what was reported here:
node-fetch/node-fetch#1743
The issue is that the
FormData
instance is being reused but since its buffer is already consumed it puts fetch into a bad state where it never actually sends the request and hangs until it hits a socket timeout of 60 seconds. The proposed fix is to always use a freshFormData
instance.In this commit I am moving the prepareFormData call to inside of the retry function so that we get a fresh FormData instance on each retry. I am hopeful that this will resolve this issue.
I added a test to cover this behavior. When I run the test before my change I observe that the test suite hangs when making this request. After my change everything works as expected. This makes me fairly confident in the value of this change.