gethostbyname 在 Mac OS X 上冻结并使用 100% CPU

发布于 2024-10-05 05:30:47 字数 684 浏览 3 评论 0原文

我有一个程序可以打开一些套接字来监听和发送。我发现了一个非常奇怪的情况,到目前为止仅在 Mac OS X 上,其中 gethostbyname 完全冻结了程序。

首先,我使用线程。其次,只有当我同时运行测试程序的两个副本时,才会出现此问题。

第一个实例创建 4 个发送套接字和 4 个接收套接字,然后它们开始相互发送流量。在我用于消息传递的网络库中,在接收端口打开后立即调用 gethostbyname() 。我发现当我启动测试程序的第二个实例时,打开 3 个接收器后,最后一个就卡在那里了。

我已将问题范围缩小到对 gethostbyname 的调用,该调用似乎永远不会返回。 (请记住,到目前为止,每次调用 gethostbyname 都工作得很好。)此外,当达到这一点时,测试程序的 CPU 使用率突然跳到 100%,就好像有是 gethostbyname 中的无限循环。另外,我无法按 Ctrl-C 控制该进程,我必须从另一个终端终止它。

显然,这种行为是不可接受的,即使它只发生在启动 8 个发送器/接收器对的极端情况下。 (一次过程中 4 个,另一个过程中 4 个。)有人以前见过这种情况吗?我怎样才能避免它?

顺便说一下,唯一测试的其他平台是 Linux (Ubuntu 10.04),它运行得很好。

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.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

陌路黄昏 2024-10-12 05:30:47

听起来您可能被这个 Oracle Java Bug 所困扰。我的解决方法是将我的 Mac 的主机名添加到 /etc/hosts

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

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"
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文