Skip to content
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: add ECONNREFUSED to list of known errors for isAvailable() #309

Merged
merged 1 commit into from
Mar 3, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ export async function isAvailable() {
'ENETUNREACH',
'ENOENT',
'ENOTFOUND',
'ECONNREFUSED',
Copy link
Contributor

Choose a reason for hiding this comment

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

Is there a complete list of these somewhere? Or are there specific ones we're trying to avoid? Wondering if we just keep adding things to this list as people report them, or if there's a better way.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I feel like I tried to dig into this once before without much success, can dig around again.

].includes(err.code)
) {
// Failure to resolve the metadata service means that it is not available.
Expand Down
33 changes: 19 additions & 14 deletions test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -244,20 +244,25 @@ it('should log error if DEBUG_AUTH is set', async () => {
assert.strictEqual(/failed, reason/.test(err!.message), true);
});

['EHOSTDOWN', 'EHOSTUNREACH', 'ENETUNREACH', 'ENOENT', 'ENOTFOUND'].forEach(
errorCode => {
it(`should fail fast on isAvailable if ${errorCode} is returned`, async () => {
const secondary = secondaryHostRequest(500);
const primary = nock(HOST)
.get(`${PATH}/${TYPE}`)
.replyWithError({code: errorCode});
const isGCE = await gcp.isAvailable();
await secondary;
primary.done();
assert.strictEqual(false, isGCE);
});
}
);
[
'EHOSTDOWN',
'EHOSTUNREACH',
'ENETUNREACH',
'ENOENT',
'ENOTFOUND',
'ECONNREFUSED',
].forEach(errorCode => {
it(`should fail fast on isAvailable if ${errorCode} is returned`, async () => {
const secondary = secondaryHostRequest(500);
const primary = nock(HOST)
.get(`${PATH}/${TYPE}`)
.replyWithError({code: errorCode});
const isGCE = await gcp.isAvailable();
await secondary;
primary.done();
assert.strictEqual(false, isGCE);
});
});

it(`should fail fast on isAvailable if 404 status code is returned`, async () => {
const secondary = secondaryHostRequest(500);
Expand Down