• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
EADDRNOTAVAIL after opening a number of sockets
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

EADDRNOTAVAIL after opening a number of sockets


  • Subject: EADDRNOTAVAIL after opening a number of sockets
  • From: Edsko de Vries <email@hidden>
  • Date: Fri, 18 May 2012 11:31:10 +0100

Hi,

I am developing a network library,and am having some strange problems
on Mac OS X that don't happen on Linux.

The library comes with a test suite. One of the tests in the suite is
approximately:

1. Create a socket, bind it to 127.0.0.1:10080, listen on it, and
spawn a thread to accept all incoming connections
2. Then repeatedly:
    2a. Create a new socket, bind it to 127.0.0.1:100xx (81, 82, ..),
listen on it, and spawn a thread to accept incoming connections
(although nobody will connect)
    2b. Three times: Create a new socket and connect it to 127.0.0.1:10080

(This may look like a strange test but it makes sense from the network
API that the library offers).

As I said, on Linux the problem proceeds without difficulties, but on
Mac OS X the call to "bind" fails at some point with EADDRNOTAVAIL.
I've inserted delays into my code and called "lsof -i TCP"
continuously to see what's going on. I ran a test with all my network
devices disabled just to avoid interference from other apps and make
it clearer what was going on. I started with just

COMMAND PID USER   FD   TYPE             DEVICE SIZE/OFF NODE NAME
launchd   1 root   19u  IPv6 0xffffff800c14ed80      0t0  TCP
localhost:ipp (LISTEN)
launchd   1 root   20u  IPv4 0xffffff800c154c20      0t0  TCP
localhost:ipp (LISTEN)

No other services had any TCP ports open (I disabled everything else).
Then at first everything works as expected. The socket created in step
1 is set up:

> TestTCP 527 edsko    4u  IPv4 0xffffff800c152fa0      0t0  TCP localhost:10080 (LISTEN)

And then the first iteration of step 2 starts. The listening socket is created:

> TestTCP 527 edsko    5u  IPv4 0xffffff800c154500      0t0  TCP localhost:10081 (LISTEN)

Then the new socket is created that we will bind on:

> TestTCP 527 edsko    6u  IPv4 0xffffff800c1536c0      0t0  TCP *:* (CLOSED)

And then that socket is bound to 10080:

< TestTCP 527 edsko    6u  IPv4 0xffffff800c1536c0      0t0  TCP *:* (CLOSED)
---
> TestTCP 527 edsko    6u  IPv4 0xffffff800c1536c0      0t0  TCP localhost:49152->localhost:10080 (ESTABLISHED)
> TestTCP 527 edsko    7u  IPv4 0xffffff800c153de0      0t0  TCP localhost:10080->localhost:49152 (ESTABLISHED)

(this is in diff format: i.e., the "CLOSED" line is replaced by the
two "ESTABLISHED" lines.) That repeats another two times, and then the
next listening socket is created:

> TestTCP 527 edsko   12u  IPv4 0xffffff800c150c00      0t0  TCP localhost:10082 (LISTEN)

and so on. The whole process repeats up to 10091, which still
completes all the way:

> TestTCP 527 edsko   75u  IPv4 0xffffff8015c0b160      0t0  TCP localhost:10091 (LISTEN)
*****
> TestTCP 527 edsko   76u  IPv4 0xffffff8015c0aa40      0t0  TCP *:* (CLOSED)
*****
< TestTCP 527 edsko   76u  IPv4 0xffffff8015c0aa40      0t0  TCP *:* (CLOSED)
---
> TestTCP 527 edsko   76u  IPv4 0xffffff8015c0aa40      0t0  TCP localhost:49182->localhost:10080 (ESTABLISHED)
> TestTCP 527 edsko   77u  IPv4 0xffffff8015c0a320      0t0  TCP localhost:10080->localhost:49182 (ESTABLISHED)
*****
> TestTCP 527 edsko   78u  IPv4 0xffffff8015c09c00      0t0  TCP *:* (CLOSED)
*****
< TestTCP 527 edsko   78u  IPv4 0xffffff8015c09c00      0t0  TCP *:* (CLOSED)
---
> TestTCP 527 edsko   78u  IPv4 0xffffff8015c09c00      0t0  TCP localhost:49183->localhost:10080 (ESTABLISHED)
> TestTCP 527 edsko   79u  IPv4 0xffffff8015c094e0      0t0  TCP localhost:10080->localhost:49183 (ESTABLISHED)
*****
> TestTCP 527 edsko   80u  IPv4 0xffffff8015c1dc20      0t0  TCP *:* (CLOSED)
*****
< TestTCP 527 edsko   80u  IPv4 0xffffff8015c1dc20      0t0  TCP *:* (CLOSED)
---
> TestTCP 527 edsko   80u  IPv4 0xffffff8015c1dc20      0t0  TCP localhost:49184->localhost:10080 (ESTABLISHED)
> TestTCP 527 edsko   81u  IPv4 0xffffff8015c1d500      0t0  TCP localhost:10080->localhost:49184 (ESTABLISHED)

but then the next attempt to 'bind' (to 10092) fails with
EADDRNOTAVAIL. lsof shows the socket created but it's still in closed
state:

> TestTCP 527 edsko   82u  IPv4 0xffffff8015c1cde0      0t0  TCP *:* (CLOSED)

This isn't something specific about port 10092, because the same thing
happens if I try a different port range. It's something to do with the
number of sockets I'm opening (although it really isn't that many), or
with the pattern, or something. I don't know and am not sure what to
google for. Any pointers would be appreciated!

Edsko
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:

This email sent to email@hidden

  • Follow-Ups:
    • Re: EADDRNOTAVAIL after opening a number of sockets
      • From: Edsko de Vries <email@hidden>
  • Prev by Date: Converting UDP unicast to broadcast with NKE
  • Next by Date: Re: EADDRNOTAVAIL after opening a number of sockets
  • Previous by thread: Converting UDP unicast to broadcast with NKE
  • Next by thread: Re: EADDRNOTAVAIL after opening a number of sockets
  • Index(es):
    • Date
    • Thread