Skip to content

Automatic retry for DNS lookup#25

Merged
jagoda merged 1 commit intolifeomic:masterfrom
jagoda:feat-dns-patching
Aug 7, 2018
Merged

Automatic retry for DNS lookup#25
jagoda merged 1 commit intolifeomic:masterfrom
jagoda:feat-dns-patching

Conversation

@jagoda
Copy link
Copy Markdown
Contributor

@jagoda jagoda commented Aug 1, 2018

No description provided.

@jagoda jagoda requested review from Druotic and mdlavin August 1, 2018 14:30
@coveralls
Copy link
Copy Markdown

coveralls commented Aug 1, 2018

Pull Request Test Coverage Report for Build 145

  • 13 of 13 (100.0%) changed or added relevant lines in 2 files are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage remained the same at 100.0%

Totals Coverage Status
Change from base Build 142: 0.0%
Covered Lines: 375
Relevant Lines: 375

💛 - Coveralls

@jagoda jagoda force-pushed the feat-dns-patching branch from 0fbb588 to d17e94e Compare August 6, 2018 15:22
@jagoda
Copy link
Copy Markdown
Contributor Author

jagoda commented Aug 6, 2018

@mdlavin @Druotic any thoughts now that tests are passing?

Comment thread src/patches/dns.js
let remaining = TRIES;

function dnsLookupWrapperResponse (error, address, family) {
if (error && error.code === dns.NOTFOUND && --remaining > 0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

It looks like some of this is implementing retry logic instead of using an existing library. Is there a reason to avoid some of the retry libraries we've used before?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

My thinking was twofold. First, using a promise-based library makes it a little more difficult/clunky to maintain the Node API interface. Second, using a dependency for a utility in an injected header like this could significantly increase the footprint of this change.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@mdlavin any thoughts on this?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

If it was me, I'd probably use an external library for the retry logic based on callbacks. I think I understand your points and I can appreciate the trade-offs. I'll approve with the code as is it.

Comment thread test/fixtures/runtime_dns.js Outdated
assert.equal(hostname, '127.0.0.1');
assert.equal(family, 4);
sinon.assert.callCount(lookup, 3);
callback(null, 'success!');
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Minor point, but a pattern I've used for callbacks in try/catch blocks is:

try {
  something
} catch (e) {
  callback(e);
  return;
}
callback(null, success)

The current code can cause a double callback if the callback(null, 'success!'); line throws an Error. That case becomes very hard to debug when it happens.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good point. I'll update this. Thanks.

Comment thread src/patches/dns.js
const dns = require('dns');
const lookup = dns.lookup;

const DELAY = 1000;
Copy link
Copy Markdown
Contributor

@Druotic Druotic Aug 7, 2018

Choose a reason for hiding this comment

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

In the context of most requests, this seems like a very long time to wait to retry a dns lookup. Should this be a smaller value, or perhaps configurable?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I considered this. The thing is that ENI cold starts are quite slow so I don't expect that retrying more frequently is very likely to succeed. I'd rather not make this configurable as I think it adds undo complexity and I don't see any value in changing this parameter between projects.

@jagoda jagoda force-pushed the feat-dns-patching branch from d17e94e to a6cc414 Compare August 7, 2018 12:33
@jagoda jagoda merged commit 2cb3138 into lifeomic:master Aug 7, 2018
@jagoda jagoda deleted the feat-dns-patching branch August 7, 2018 17:32
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.

4 participants