Abort DNS lookup on request abort
- Dominant language
- JavaScript
- Stars
- 402
- Forks
- 49
- PR merge metrics
- No merged PRs in 30d
Description
https://github.com/feross/simple-get/blob/e7a74115ca9dd28720f186275c5a67df81985426/index.js#L74-L77
This calls `abort` on the request, and fires the callback. So you'd expect `simpleGet` to have relinquished all execution back to the caller.
But in a super simple example of simply making a request to some URL, and exiting (nothing more), there is an observed 30s delay between when the callback is called with the error and before the process exits.
I looked into it, and it appears this is caused by the fact that the `http` module from node [defaults to `dns.lookup`](https://github.com/nodejs/node/blob/5bae73df902060070120d6b393a760c9ebd2d242/lib/net.js#L1351) which is not cancellable.
I experimented with swapping this out with [`Tangerine`](https://github.com/forwardemail/nodejs-dns-over-https-tangerine) which maintains an internal `AbortController` and adding a `tangerine.cancel()` on any error and it worked flawlessly.
Slight hiccup though - tangerine's peer dependency is [`undici`](https://github.com/nodejs/undici) so it might be unfortunate to pull that in if you're not using it. Ref: https://github.com/feross/simple-get/issues/64
But there's other DNS alternatives that don't require undici. Up to you, just figured I'd mention this here.
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at index.js lines 74-77 and trace how simpleGet aborts the Node http request while http still uses the non-cancellable dns.lookup. Compare the reported Tangerine approach and other DNS alternatives, then reproduce the simple request case. Done means an aborted lookup no longer keeps the process alive for the observed 30 seconds without introducing an unsuitable dependency.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- javascript, node.js
- Domain
- networking
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100