Skip to content

feat(datafile manager): Add request timeouts #268

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 11 commits into from
May 13, 2019
Merged

Conversation

mjc1283
Copy link
Contributor

@mjc1283 mjc1283 commented May 10, 2019

Summary

This adds a 60 second timeout to all requests made by the datafile manager. In the browser, we assign to the timeout property of the XHR. In node, we set our own timeout, and abort the request when the timeout fires.

The response promise is rejected when the request times out.

Test plan

Manual & unit tests

Issues

https://optimizely.atlassian.net/browse/OASIS-4685

@mjc1283 mjc1283 requested review from mikeproeng37 and a team May 10, 2019 19:21
@coveralls
Copy link

Coverage Status

Coverage remained the same at 97.58% when pulling c3dcb25 on mcarroll/request-timeouts into bfebb68 on master.

@@ -25,12 +25,12 @@
},
"devDependencies": {
"@types/jest": "^24.0.9",
"@types/nise": "^1.4.0",
Copy link
Contributor

Choose a reason for hiding this comment

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

Nise!

const scope = nock(host)
.get(path)
.delay(61000)
.reply(200, '{"foo":"bar"}')
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: do you actually need to reply if it's gunna just time out

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Not sure how to implement this test without calling reply. From what I can tell, the 'request' event is not emitted on the scope object when I don't call reply.

@@ -21,3 +21,5 @@ export const MIN_UPDATE_INTERVAL = 1000
export const DEFAULT_URL_TEMPLATE = `https://cdn.optimizely.com/datafiles/%s.json`

export const BACKOFF_BASE_WAIT_SECONDS_BY_ERROR_COUNT = [0, 8, 16, 32, 64, 128, 256, 512]

export const REQUEST_TIMEOUT_MS = 60 * 1000 // 1 minute
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: DEFAULT_REQUEST_TIME_MS?

const timeout = setTimeout(() => {
request.abort()
reject(new Error('Request timed out'))
}, REQUEST_TIMEOUT_MS)
Copy link
Contributor

Choose a reason for hiding this comment

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

I think we should make this configurable and have it injected in by the datafile manager. That we this doesn't have to rely directly on the config file

Copy link
Contributor

Choose a reason for hiding this comment

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

Chatted offline about doing this as a later refactor to keep the scope of this small.

@mjc1283 mjc1283 requested a review from jordangarcia May 10, 2019 21:52
@mjc1283 mjc1283 merged commit 4e8bd24 into master May 13, 2019
@mjc1283 mjc1283 deleted the mcarroll/request-timeouts branch May 13, 2019 19:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants