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

Add timeout to DNS Resolver #2

Merged
merged 1 commit into from
Jan 28, 2024
Merged
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
11 changes: 6 additions & 5 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
// dns-lists plugin

const dns = require('dns').promises;
const net = require('net');
const net_utils = require('haraka-net-utils');
const dnsPromises = require('dns').promises;
const dns = new dnsPromises.Resolver({timeout: 25000, tries: 1});

exports.disable_allowed = false;
let redis_client;
Expand Down Expand Up @@ -184,9 +185,9 @@ exports.lookup = async function (ip, zone) {
catch (err) {
this.stats_incr_zone(err, zone, start); // Statistics

if (err.code === dns.NOTFOUND) return; // unlisted, not an error
if (err.code === dnsPromises.NOTFOUND) return; // unlisted, not an error

if (err.code === dns.TIMEOUT) { // list timed out
if (err.code === dnsPromises.TIMEOUT) { // list timed out
this.disable_zone(zone, err.code); // disable it
return
}
Expand Down Expand Up @@ -313,9 +314,9 @@ exports.checkZoneNegative = async function (zone, ip) {
}
catch (err) {
switch (err.code) {
case dns.NOTFOUND: // IP not listed
case dnsPromises.NOTFOUND: // IP not listed
return true
case dns.TIMEOUT: // list timed out
case dnsPromises.TIMEOUT: // list timed out
this.disable_zone(zone, err.code)
}
console.error(`${query} -> got err ${err}`)
Expand Down
Loading