开发者

gethostbyname freezes and uses 100% CPU on Mac OS X

I have a program which opens a few sockets to listen and开发者_如何转开发 send on. I've found a very strange condition, so-far only on Mac OS X, where gethostbyname completely freezes the program.

Firstly, I am not using threads. Secondly, the problem only happens if I run two copies of my test program at once.

The first instance creates 4 sending and 4 receiving sockets, and then they commence sending traffic to each other. In the network library I am using for messaging, gethostbyname() is called just after the receiving port is opened. I found that when I started a second instance of the test program, after opening 3 receivers, the last one just stuck there.

I've narrowed the problem down to the call to gethostbyname, which seemingly never returns. (Keep in mind that it worked fine for every call to gethostbyname up to this point.) Also, when it hits this point, suddenly the CPU usage of the test program jumps to 100%, as if there is an infinite loop in gethostbyname. Additionally I can't Ctrl-C the process, I have to kill it from another terminal.

Obviously this behaviour is unacceptable, even if it only occurs in this extreme case of starting 8 sender/receiver pairs. (4 in once process, 4 in another.) Has anyone seen this before and how can I avoid it?

By the way the only other platform tested is Linux (Ubuntu 10.04), where it runs just fine.


It sounds like you might have been stung by this Oracle Java Bug. My workaround was to add the hostname of my Mac to /etc/hosts

sudo bash -c "echo 127.0.0.1 $HOSTNAME >> /etc/hosts"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜