-
Notifications
You must be signed in to change notification settings - Fork 83
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
Conversation
access to timeout property on fake XHR.
@@ -25,12 +25,12 @@ | |||
}, | |||
"devDependencies": { | |||
"@types/jest": "^24.0.9", | |||
"@types/nise": "^1.4.0", |
There was a problem hiding this comment.
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"}') |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
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