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

socket.bind() with bogus or unavailable address fails silently #17

Open
timbowhite opened this issue Apr 5, 2019 · 2 comments · May be fixed by #18
Open

socket.bind() with bogus or unavailable address fails silently #17

timbowhite opened this issue Apr 5, 2019 · 2 comments · May be fixed by #18

Comments

@timbowhite
Copy link

timbowhite commented Apr 5, 2019

Calling socket.bind with a bogus or unavailable address causes the process to fail silently. Example:

'use strict';

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

new Promise(function (fulfill, reject){
    socket.on('error', reject);

    try{
        socket.bind(null, '8.8.8.8', fulfill);
    }
    catch(e){
        return reject(e);
    }
})
.then(function(){
    console.log('socket bound');
    socket.destroy();
})
.catch(function(err){
    console.log('caught error', err);
});

When I run this with Node 6, there is no output, no errors caught, and the script exits prematurely. Looks like dns-socket emits a 'warning' instead of an 'error' in this case.

PR incoming.

Edit: just my $.02: I think this function in index.js should not try to pick/choose which errors constitute emitting a warning vs. an error, but should always emit an error instead:

  function onerror (err) {
    if (err.code === 'EACCES' || err.code === 'EADDRINUSE') {
      self.emit('error', err)
    } else {
      self.emit('warning', err)
    }
  }
@silverwind
Copy link
Collaborator

I think I agree, especially because those "warning" or "error" events are not documented.

@mafintosh any specific reason why some errors emit only warnings?

@mafintosh
Copy link
Owner

it's because the UDP socket can emit some weird errors based on what you pass in to .send, if I always whitelist those. Unsure if that is still the issue with newer node versions.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants