Skip to content

socket.bind() + bound address becomes unavailable + query = indefinite hang #19

@timbowhite

Description

@timbowhite

BTW thanks for this module.

If you socket.bind() to a local address, and then the interface becomes unavailable (ie. network goes down, network interface no longer available, cable unplugged, etc), and you then run a query, the query will hang indefinitely.

Example:

'use strict';

const dnsSocket = require('.')
const socket = dnsSocket({retries: 0, timeout: 5000});

// bind to some local address, 192.168.0.2 in this case, adjust accordingly
new Promise(function (fulfill, reject){
    socket.on('error', reject);
    socket.on('listening', fulfill);
    socket.bind(null, '192.168.0.2');
})
// do something like unplug your network cable
// to make the bound address --> EADDRNOTAVAIL 
.then(function(){
    console.log('socket bound');
    console.log('to reproduce, kill your network connection within the next 5 seconds');
    return new Promise(function(resolve, reject) {
        setTimeout(resolve, 5000);
    });
})
// make a query, it'll hang indefinitely
.then(function(){
    console.log('making socket query, should hang indefinitely');
    return new Promise(function(resolve, reject) {
        socket.query({
              questions: [{
                type: 'A',
                name: 'google.com'
              }]
            },
            53,
            '1.1.1.1',
            function(err, res){
                if (err) return reject(err);
                resolve(res);
            }
        );
    });
})
.then(function(res){
    console.log('got response', res);
    console.log('all done, destroy socket');
    socket.destroy();
})
.catch(function(err){
    console.log('caught error', err);
    socket.destroy();
});

Output:

socket bound
to reproduce, kill your network connection within the next 5 seconds
making socket query, should hang indefinitely

To reproduce, you'll need to:

  1. replace '192.168.0.2' with your local IP address
  2. unplug your network cable/kill your network connection when prompted

I think I see the issue, PR incoming.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions