-
Notifications
You must be signed in to change notification settings - Fork 653
closing a shared socket can lead to 100% CPU usage #1099
Comments
+1 |
Are you sure that the supplied javascript code sample is reproducing the problem? Seems to be working just fine for me. Also, I don't understand how this patch is fixing a problem, could you please explain what it does in a little bit more detail? |
Sorry, I should have specified that this only happens on Linux (not sure what system you're on). The testcase works for me (causes 100% cpu usage) on node 0.10.25, on every machine I tried. The problem occurs because the fd stays regstered with epoll despite being closed; the patch deregisters it from the epoll instance entirely. |
I don't believe this is any longer the case [1][2]. Or is it only that fd's won't be shared from master to child? [1] 6abe1e4 |
@trevnorris this is what actually happening, because And I think that this is a kernel bug, will try on a newer linux just to verify it. |
Linux 7527bd77-ab3e-474b-ace7-eed6053931e7 3.1.10joyent-ubuntu-10-opt #1 SMP Fri Jan 20 09:55:31 PST 2012 x86_64 GNU/Linux |
It's not a bug but it's definitely a quirk. epoll polls on file descriptions, not file descriptors. If the file description is alive because of a file descriptor in another process, then any activity on the file description wakes up epoll_wait() in your process. The fun thing is, epoll_ctl(EPOLL_CTL_DEL) won't work if your file descriptor is already closed. You can mitigate it somewhat by switching to edge-triggered mode. That doesn't really solve the issue but at least you won't get repeated wake-ups, just a single one. |
It happens for me on node |
So this is an expected behavior?! The epoll is totally screwed then :) Especially considering that I could open a socket/file with the same fd as of the closed one and receive events for stale closed fd. Anyway, I think that the only thing we could do is to call @goffrie if you wish - you could contribute a Pull Request and I'll review it and land it, but if you don't have time for this - just let me know and I'll fix it myself. |
That will catch most of it. There are some edge cases like dup'ed stdio file descriptors that probably need to be addressed separately. I remember looking into that some months ago but the details are a little fuzzy by now. |
Hm... what's up with |
I created #1100. |
@bnoordhuis yeah, confirming https://gist.github.com/indutny/8842007 . Seems like it is an intended behavior. |
And a quote from man page:
|
It's in a 0.10 release already, though I can't remember the version number
|
@goffrie I found the commit, thank you :) |
Another manifestation of #826. When a socket is closed in one process, if it is open in another process, it may stay registered in epoll and thus continously generate junk events that can't be silenced. Reproducible by the following node.js program:
This patch corrects this behaviour, although as I understand it, it is not acceptable as-is because of the performance of the extra system call.
The text was updated successfully, but these errors were encountered: