anyway to catch: Error: EADDRNOTAVAIL, Cannot assign requested address

577 views
Skip to first unread message

gotrich

unread,
Sep 9, 2011, 1:21:21 PM9/9/11
to nodejs
Doing a try/catch around this code. Doesn't catch. Catching "uncaught"
in the main seems unwieldy versus catching it in the method trying to
use the connection and handling gracefully.

try{
this.conn = net.createConnection(this.port,
this.address);
} catch (e){ // never gets caught }


Error: EADDRNOTAVAIL, Cannot assign requested address
at doConnect (net.js:555:5)
at net.js:731:9
at Object.lookup (dns.js:159:5)
at Socket.connect (net.js:718:20)
at Object.createConnection (net.js:265:5)

Oleg Podsechin

unread,
Sep 9, 2011, 8:48:54 PM9/9/11
to nod...@googlegroups.com
Due to Node's asynchronous nature, the error isn't thrown, but rather passed via a callback.

You need to go: this.conn.on('error', function(e) { ... });

If you would prefer to use a synchronous style with exceptions then perhaps it may be worth giving my common-node package a go.

I don't have a socket client example ready, but a server looks like this: https://github.com/olegp/common-node/blob/master/examples/chat.js

Oleg


gotrich

unread,
Sep 9, 2011, 10:54:47 PM9/9/11
to nodejs

Oleg,

Yeah, that part I get, but the problem (or bug) is the EADDRNOTAVAIL
is not caught in my connection error handler (which I've setup as you
mention)

Ryan, anyone , is this a known bug?

Thanks,

Ric

Ben Noordhuis

unread,
Sep 9, 2011, 11:01:48 PM9/9/11
to nod...@googlegroups.com
On Sat, Sep 10, 2011 at 04:54, gotrich <rich....@gmail.com> wrote:
>
> Oleg,
>
> Yeah, that part I get, but the problem (or bug) is the EADDRNOTAVAIL
> is not caught in my connection error handler (which I've setup as you
> mention)
>
> Ryan, anyone , is this a known bug?

No. You didn't mention what version of Node you're testing this with,
but it shouldn't happen with 0.4.11 or the latest master. If you can
turn it into a reproducible (and stand-alone, no third-party
dependencies) test case, please open an issue in the bug tracker.

Florian Traverse

unread,
Sep 10, 2011, 5:34:11 AM9/10/11
to nod...@googlegroups.com

From my experience, you have to set your on('error') before the listen() to be 100% sure it takes all errors in account, notably this one. Fixed the problem for me

Le 10 sept. 2011 03:02, "Ben Noordhuis" <in...@bnoordhuis.nl> a écrit :

gotrich

unread,
Sep 10, 2011, 6:21:39 PM9/10/11
to nodejs
node -v : v0.4.11

the test case is a bit harder to reproduce, as it's happening when our
system is running out of resources/ports, but EADDRNOTAVAIL is thrown,
and it's not caught in anything but process.on("uncaughtException") in
our main app, which is unhelpful/unwise to recover from at that point.



rich



On Sep 10, 2:34 am, Florian Traverse <florian.trave...@gmail.com>
wrote:
> From my experience, you have to set your on('error') before the listen() to
> be 100% sure it takes all errors in account, notably this one. Fixed the
> problem for me
>
> Le 10 sept. 2011 03:02, "Ben Noordhuis" <i...@bnoordhuis.nl> a écrit :

gotrich

unread,
Sep 10, 2011, 6:22:41 PM9/10/11
to nodejs
Florian,

Agreee, but the exception is thrown on the net.createConnection()
call....before any listen()

Rich

On Sep 10, 2:34 am, Florian Traverse <florian.trave...@gmail.com>
wrote:
> From my experience, you have to set your on('error') before the listen() to
> be 100% sure it takes all errors in account, notably this one. Fixed the
> problem for me
>
> Le 10 sept. 2011 03:02, "Ben Noordhuis" <i...@bnoordhuis.nl> a écrit :
Reply all
Reply to author
Forward
0 new messages