mafintosh / mafintosh/dns-socket

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

Open
#19 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
106
Forks
18
PR merge metrics
No merged PRs in 30d

Description

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.

Contributor guide

No contributing guide indexed for this repository

Research direction

Reproduce the example using socket.bind() and socket.query() while making the bound interface unavailable, then read the bind and query paths and their timeout or error handling. Done means the query terminates with an observable error or timeout instead of hanging indefinitely, including for the demonstrated network-loss scenario.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript
Domain
networking
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.