Skip to content

Commit

Permalink
Disable /etc/hosts file temporarily
Browse files Browse the repository at this point in the history
The `hostile` libary is broken as it never closes the files it
opens and thus after some time we get:

```
EMFILE: too many open files, open '/etc/hosts'
```
  • Loading branch information
OlliV committed May 23, 2018
1 parent 7a9adf4 commit 573169b
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 24 deletions.
23 changes: 0 additions & 23 deletions index.js
@@ -1,5 +1,4 @@
const dns = require('dns');
const hostfile = require('@zeit/cached-hostfile');
const retry = require('async-retry');
const LRU = require('lru-cache');

Expand All @@ -13,17 +12,6 @@ const cache6 = LRU(lruOptions);

function resolve4(host, resolver) {
return new Promise((resolve, reject) => {
// Try to resolve from the hostfile
const localips = hostfile.resolve4(host);
if (localips) {
return resolve(localips.map(ip => {
return {
address: String(ip),
ttl: HOSTFILE_RESULT_TTL
};
}));
}

resolver.resolve4(host, { ttl: true }, (err, res) => {
if (err) return reject(err);
resolve(res);
Expand All @@ -33,17 +21,6 @@ function resolve4(host, resolver) {

function resolve6(host, resolver) {
return new Promise((resolve, reject) => {
// Try to resolve from the hostfile
const localips = hostfile.resolve6(host);
if (localips) {
return resolve(localips.map(ip => {
return {
address: String(ip),
ttl: HOSTFILE_RESULT_TTL
};
}));
}

resolver.resolve6(host, { ttl: true }, (err, res) => {
if (err) return reject(err);
resolve(res);
Expand Down
1 change: 0 additions & 1 deletion package.json
Expand Up @@ -9,7 +9,6 @@
"main": "index.js",
"author": "Olli Vanhoja",
"dependencies": {
"@zeit/cached-hostfile": "^0.1.0",
"async-retry": "1.1.3",
"lru-cache": "4.1.1"
},
Expand Down

0 comments on commit 573169b

Please sign in to comment.