Skip to content

Commit

Permalink
Make the promise.cancel() method actually work (#42)
Browse files Browse the repository at this point in the history
  • Loading branch information
Lucas Barrena authored Mar 30, 2020
1 parent 7d8f53a commit c4303d5
Showing 1 changed file with 7 additions and 1 deletion.
8 changes: 7 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,16 +83,22 @@ const queryDns = (version, options) => {

const socket = dns({
retries: 0,
maxQueries: 1,
socket: dgram.createSocket(version === 'v6' ? 'udp6' : 'udp4'),
timeout: options.timeout
});
socket.retries = 0; // Temp fix, pull request: https://github.com/mafintosh/dns-socket/pull/22

const socketQuery = promisify(socket.query.bind(socket));

const promise = (async () => {
for (const dnsServerInfo of data.dnsServers) {
const {servers, question} = dnsServerInfo;
for (const server of servers) {
if (socket.destroyed) {
return;
}

try {
const {name, type, transform} = question;

Expand Down Expand Up @@ -125,7 +131,7 @@ const queryDns = (version, options) => {
})();

promise.cancel = () => {
socket.cancel();
socket.destroy();
};

return promise;
Expand Down

0 comments on commit c4303d5

Please sign in to comment.