Skip to content
This repository has been archived by the owner on Jan 12, 2021. It is now read-only.

feat: Retry requests in more situations #39

Merged
merged 7 commits into from
May 16, 2019
Merged

Conversation

bengourley
Copy link
Contributor

@bengourley bengourley commented May 7, 2019

This flips the retry logic from a flag that says "retry me", to a flag that says "don't retry me" –
and only if the "don't retry me" flag exists do we not retry. A couple of test cases are added for
new cases where we now retry, such as socket timeouts and socket hangups.

Also TIL:

Assigning a property on process.env will implicitly convert the value to a string.

Source: Node.js Process docs

So the env vars that are set in testing which are expected to be integers are now parsed as such.

This flips the retry logic from a flag that says "retry" me, to a flag that says "don't retry me" –
and only if the "don't retry me" flag exists do we not retry. A couple of test cases are added for
new cases where we now retry, such as socket timeouts and socket hangups.
Copy link
Contributor

@sazap10 sazap10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whilst the change seems fine to me, after doing some testing it doesn't seem to be behaving as I would expect it to. Starting the upload whilst the upload server is not running and starting the upload server within the retry limit causes an "ESOCKETTIMEDOUT" error even if the upload server is running correctly. I don't know whether its request which is the issue or the server.

@bengourley
Copy link
Contributor Author

Big update to this PR.

In investigating the issue mentioned by @sazap10 I ripped out request and replaced it with the send() implementation in bugsnag-build-reporter since that implementation was working in bugsnag/bugsnag-build-reporter-node#5 – it just uses the built-in http/https modules.

Because this library does multipart uploads I had to use the form-data module in addition (which was already included as a transistive dependency of request). It still was failing and I managed to track it down to the fact that prepareRequest() was making a single readstream to consume the source map file data which was being reused across attempts – meaning the data was consumed by the first attempt and there was nothing to be sent on subsequent attempts.

The fix is to call prepareRequest() every time a retry is attempted.

Since I went to the effort of removing request – it's quite a bloaty library – I think it makes sense to leave it out as we simply don't need it.

Copy link
Contributor

@sazap10 sazap10 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

SFTM, works fine with the upload server not being available when starting the upload and becoming available within the retry window.

@bengourley bengourley merged commit 3967849 into master May 16, 2019
@bengourley bengourley deleted the bengourley/retry branch May 16, 2019 08:46
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants