-
Notifications
You must be signed in to change notification settings - Fork 5
Feat add exp 429 retry #46
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -75,6 +75,7 @@ export default abstract class WebDriverRequest extends EventEmitter { | |
| fullRequestOptions = options.transformRequest(fullRequestOptions) | ||
| } | ||
|
|
||
| fullRequestOptions.exp429RetryBaseDelay = options.exp429RetryBaseDelay | ||
| this.emit('request', fullRequestOptions) | ||
| return this._request(fullRequestOptions, options.transformResponse, options.customWdRequestAgent, options.connectionRetryCount, 0) | ||
| } | ||
|
|
@@ -178,7 +179,7 @@ export default abstract class WebDriverRequest extends EventEmitter { | |
| log.info('DATA', transformCommandLogResult(fullRequestOptions.json)) | ||
| } | ||
|
|
||
| const { url, retry: _, ...requestLibOptions } = fullRequestOptions | ||
| const { url, retry: _, exp429RetryBaseDelay: __, ...requestLibOptions } = fullRequestOptions | ||
| const startTime = this._libPerformanceNow() | ||
| let response = customWdRequestAgent | ||
| ? await customWdRequestAgent.request(url!, requestLibOptions).catch((err: RequestLibError) => err) | ||
|
|
@@ -207,6 +208,16 @@ export default abstract class WebDriverRequest extends EventEmitter { | |
| this.emit('performance', { request: fullRequestOptions, durationMillisecond, success: false, error, retryCount }) | ||
| log.warn(msg) | ||
| log.info(`Retrying ${retryCount}/${totalRetryCount}`) | ||
|
|
||
| const exp429RetryBaseDelay = fullRequestOptions.exp429RetryBaseDelay | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I suggest changing the name of this variable it's too complicated |
||
| if (exp429RetryBaseDelay && !(response instanceof Error) && response.statusCode === 429) { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are we here retraying absolutely all requests, not just for creating a session? |
||
| const delay = Math.round(exp429RetryBaseDelay * 2 ** (retryCount - 1) + Math.random() * 100) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why is the jitter so low? Only 100ms |
||
| log.warn(`Session creation failed with 429, retrying in ${delay}ms`) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Are you sure we need a warning here, not a debug log? |
||
| return new Promise(resolve => setTimeout(resolve, delay)).then( | ||
| () => this._request(fullRequestOptions, transformResponse, customWdRequestAgent, totalRetryCount, retryCount) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why not just delete this call and use the call of |
||
| ) | ||
| } | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. what if tomorrow we let the user manage |
||
|
|
||
| return this._request(fullRequestOptions, transformResponse, customWdRequestAgent, totalRetryCount, retryCount) | ||
| } | ||
|
|
||
|
|
||
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 suggest removing the option and leaving only the constant value. In my opinion, there is no reason for a new option.