-
Notifications
You must be signed in to change notification settings - Fork 2.4k
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
feat(http): Support for Retry-After
header
#25859
Conversation
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 need to check got retry, it's doing 2 retries by default which shouldn't happen when we get a retry after header.
Live test
import httpServer from 'http';
import { Http } from './util/http';
let countdown = 2;
const server = httpServer
.createServer(function (req, res) {
if (countdown === 0) {
// eslint-disable-next-line no-console
console.log('Response 200');
res.writeHead(200, { 'Content-Type': 'application/json' });
res.end(JSON.stringify({ msg: 'Hello World' }));
server.closeAllConnections();
server.close();
} else {
// eslint-disable-next-line no-console
console.log('Response 429');
countdown -= 1;
res.writeHead(429, {
'Content-Type': 'application/json',
'retry-after': '5',
});
res.end(JSON.stringify({ msg: 'Too Many Requests' }));
}
})
.listen(1337, '127.0.0.1');
const client = new Http('foobar');
client
.get('http://127.0.0.1:1337/')
.then((res) => {
// eslint-disable-next-line no-console
console.log(res);
return 0;
})
.catch((err) => {
// eslint-disable-next-line no-console
console.error(err);
}); ❯ time pnpm ts-node lib/test.ts
Response 429
Response 429
Response 200
{
statusCode: 200,
body: '{"msg":"Hello World"}',
headers: {
'content-type': 'application/json',
date: 'Sun, 19 Nov 2023 20:28:53 GMT',
connection: 'keep-alive',
'keep-alive': 'timeout=5',
'transfer-encoding': 'chunked'
},
authorization: false
}
pnpm ts-node lib/test.ts 0.84s user 0.13s system 9% cpu 10.762 total |
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.
- Should also work for GitHub secondary rate limit, which I think is a 401
- Make sure logging is adequate whenever this happens
Co-authored-by: Rhys Arkins <[email protected]>
Co-authored-by: Rhys Arkins <[email protected]>
wrapWithRetry function
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.
Any way to test this in practice?
Co-authored-by: HonkingGoose <[email protected]>
|
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.
Does this work if there are concurrent requests to the same host, e.g. a datasource rate limit and we have multiple requests to the same datasource?
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.
otherwise LGTM
When the first response is received, any further request will be made after the delay. None of the queueing is done for now, i.e. they will fire simultaneously after the delay. |
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.
otherwise LGTM
Co-authored-by: Sebastian Poxhofer <[email protected]>
@rarkins can we get this done please? |
@viceice please check the outstanding conversation to be resolved |
we now retry for any 4xx error that's fine by me |
🎉 This PR is included in version 37.93.0 🎉 The release is available on:
Your semantic-release bot 📦🚀 |
Co-authored-by: Rhys Arkins <[email protected]> Co-authored-by: HonkingGoose <[email protected]> Co-authored-by: Michael Kriese <[email protected]> Co-authored-by: Sebastian Poxhofer <[email protected]>
Changes
Retry-After
headermaxRetryAfter
option via host rulesContext
Documentation (please check one with an [x])
How I've tested my work (please select one)
I have verified these changes via: