<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Oct 9, 2014 at 4:28 PM, David T. Lewis <span dir="ltr">&lt;<a href="mailto:lewis@mail.msen.com" target="_blank">lewis@mail.msen.com</a>&gt;</span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class=""><br>
On Thu, Oct 09, 2014 at 03:27:05PM -0700, Eliot Miranda wrote:<br>
&gt;<br>
&gt; Hi Both,<br>
&gt;<br>
</span><span class="">&gt; On Thu, Oct 9, 2014 at 3:05 PM, G??ran Krampe &lt;<a href="mailto:goran@krampe.se">goran@krampe.se</a>&gt; wrote:<br>
&gt;<br>
&gt; &gt;<br>
&gt; &gt; Hi guys!<br>
&gt; &gt;<br>
&gt; &gt; Long email but... work for hire here! :)<br>
&gt; &gt;<br>
&gt; &gt; In short:<br>
&gt; &gt;<br>
&gt; &gt; Ron and I (3DICC) have a problem with the Unix VM networking and I am<br>
&gt; &gt; reaching out before burning too many hours on something one of you<br>
&gt; &gt; C-Unix/Socket/VM guys can fix in an afternoon - and earn a buck for your<br>
&gt; &gt; trouble.<br>
&gt; &gt;<br>
&gt;<br>
&gt; Cool.  This is likely easy to fix.  Your image is running out of file<br>
&gt; descriptors.  Track open and close calls, e.g. add logging around at<br>
&gt; least StandardFileStream&gt;&gt;#primOpen:writable:<br>
&gt; , AsyncFile&gt;&gt;#primOpen:forWrite:semaIndex:,<br>
&gt; Socket&gt;&gt;#primAcceptFrom:receiveBufferSize:sendBufSize:semaIndex:readSemaIndex:writeSemaIndex:<br>
&gt; and their associated close calls and see what&#39;s being opened without being<br>
&gt; closed.  It shoudl be easy to track=down, but may be more difficult to fix.<br>
&gt;<br>
&gt; Good luck!<br>
<br>
</span>I agree with what Eliot is saying and would add a few thoughts:<br>
<br>
- Don&#39;t fix the wrong problem (DFtWP). Unless you have some reason to<br>
believe that this server application would realistically have a need to<br>
handle anything close to a thousand concurrent TCP sessions, don&#39;t fix<br>
it by raising the per-process file handle limit, and don&#39;t fix it by<br>
reimplementing the socket listening code.<br>
<br>
- It is entirely possible that no one before you has ever tried to run<br>
a server application with the per-process file handle limit bumped up<br>
above the default 1024. So if that configuration does not play nicely<br>
with the select() mechanism, you may well be the first to have encountered<br>
this as an issue. But see above, don&#39;t fix it if it ain&#39;t broke.<br>
<br>
- Most &quot;out of file descriptor&quot; problems involve resource leaks (as Eliot<br>
is suggesting), and in those cases you will see a gradual increase in file<br>
descriptors in /proc/&lt;vmpid&gt;/fd/ over time. Eventually you run out of<br>
descriptors and something horrible happens.<br>
<br>
- Before doing anything else, you must confirm if this is a resource leak,<br>
with file descriptor use continuously increasing (which is what Eliot and<br>
I are both assuming to be the case here), or if it is a real resource<br>
issue in which your server has a legitimate need to maintain a very large<br>
number of TCP connections concurrently. Given that you have a running<br>
application with real users, you will probably want to do this with something<br>
like a shell script keeping track of the /proc/&lt;pid&gt;/fd/ directory for<br>
the running VM. (In <a href="http://squeaksource.com" target="_blank">squeaksource.com</a>, there is an undiagnosed file handle<br>
leak similar to what I think you are experiencing. My kludgy workaround is<br>
a process in the image that uses OSProcess to count entries in /proc/&lt;pid&gt;/fd/<br>
and restart the image when the file descriptor situation becomes dire).<br>
<br>
- Finding file (socket) handle leaks is trickly, and if you have customers<br>
depending on this, you probably do not have the luxury of fixing it right.<br>
Is there any way to periodically restart the server image without causing<br>
pain to the customer? If so, consider a kludgy workaround like I did for<br>
squeaksource. Monitor the VM process for file handle leaks and restart<br>
it proactively rather than waiting for a catastrophic failure. You can<br>
do this all from within the image, I will dig out my squeaksource hack if<br>
you think it may be of any help.<br>
<br>
- Sorry to repeat myself but this is by far the most important point: DFtWP.<br></blockquote><div><br></div><div>Great message David.  You&#39;ve nailed it.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Dave<br>
<div><div class="h5"><br>
&gt;<br>
&gt;<br>
&gt; &gt; In looong:<br>
&gt; &gt;<br>
&gt; &gt; So... we are running a large deployment of Terf (yay!) that is &quot;pushing&quot;<br>
&gt; &gt; the server side VMs a bit. The large load has caused us to experience some<br>
&gt; &gt; issues.<br>
&gt; &gt;<br>
&gt; &gt;<br>
&gt; &gt; Our Possibly Faulted Analysis So Far<br>
&gt; &gt; ====================================<br>
&gt; &gt;<br>
&gt; &gt; One of our server side VMs, the one that unfortunately is a crucial<br>
&gt; &gt; resource, locks up and doesn&#39;t respond on its most important listening<br>
&gt; &gt; Socket port. VM does not crash however. We reboot it, because its a<br>
&gt; &gt; stressful situation with LOTS of users being affected, so we haven&#39;t looked<br>
&gt; &gt; &quot;inside&quot;.<br>
&gt; &gt;<br>
&gt; &gt; Unfortunately the shell script starting the VMs wasn&#39;t catching stderr to<br>
&gt; &gt; a log file (Argh! Now it does though so we will see if we get more info<br>
&gt; &gt; later) so we have missed some info here but Ron &quot;got lucky&quot; and saw this on<br>
&gt; &gt; his terminal (stderr of the VM going to his terminal instead of log file):<br>
&gt; &gt;<br>
&gt; &gt; &quot;errno 9<br>
&gt; &gt; select: Bad file descriptor&quot;<br>
&gt; &gt;<br>
&gt; &gt; It took us quite some time before we realized this was indeed Squeak<br>
&gt; &gt; talking, and that it was from inside aio.c - a call from aioPoll():<br>
&gt; &gt;         perror(&quot;select&quot;)<br>
&gt; &gt;<br>
&gt; &gt; ...ok. Some important background info:<br>
&gt; &gt;<br>
&gt; &gt; Before this we hit the default ulimit of 1024 per user (duh!), causing<br>
&gt; &gt; &quot;Too Many Files Open&quot;, so we raised them silly high. That did make the<br>
&gt; &gt; system handle itself - but in retrospect we think another issue (related to<br>
&gt; &gt; SAML auth) caused tons of client requests getting spawned from this VM and<br>
&gt; &gt; thus is what made us reach the limit in the first place. It may also have<br>
&gt; &gt; been the factor (=many many sockets) that in the end caused the errno 9<br>
&gt; &gt; described above - see below for reasoning.<br>
&gt; &gt;<br>
&gt; &gt; After perusing the IMHO highly confusing :) Socket code (no offense of<br>
&gt; &gt; course, its probably trivial to a Unix C-guru) at least we understand that<br>
&gt; &gt; the code uses select() and not a more modern poll() or epoll(). In fact<br>
&gt; &gt; there is also a call to select() in sqUnixSocket.c, but... probably not<br>
&gt; &gt; relevant.<br>
&gt; &gt;<br>
&gt; &gt; Yeah, epoll() is not portable etc, we know, but frankly we only care for<br>
&gt; &gt; Linux here.<br>
&gt; &gt;<br>
&gt; &gt; Googling shows us further that select() has issues, I mean, yikes. And the<br>
&gt; &gt; thing I think we might be hitting here is the fact that select() doesn&#39;t<br>
&gt; &gt; handle more than 1024 file descriptors!!! (as far as I can understand the<br>
&gt; &gt; writing on the Internet) and to make it worse, it seems to be able to go<br>
&gt; &gt; bananas if you push it there...<br>
&gt; &gt;<br>
&gt; &gt; Now... again, Internet seems to imply that the &quot;usual&quot; cause of &quot;errno 9&quot;<br>
&gt; &gt; is doing a select on an fd that has already been closed. Typical bug<br>
&gt; &gt; causing this is accidentally closing an fd twice - and thus, if you are<br>
&gt; &gt; unlucky, accidentally the second time closing the fd when it actually has<br>
&gt; &gt; already managed to get reused and thus is open agian. Oops.<br>
&gt; &gt;<br>
&gt; &gt; But it seems unreasonable to think that *such* a bug exists in this code<br>
&gt; &gt; after all these years. And I am simply guessing its the &gt;1024 fd problem<br>
&gt; &gt; biting us, but yeah, we don&#39;t know. And I also guess it was that SAML<br>
&gt; &gt; issue, in combination with raised ulimits, that made us even get over 1024.<br>
&gt; &gt;<br>
&gt; &gt; Things we are planning:<br>
&gt; &gt;<br>
&gt; &gt; - Come up with a test case showing it blowing up. Will try to do that next<br>
&gt; &gt; week.<br>
&gt; &gt; - Start looking at how to use poll() or epoll() instead, because we need<br>
&gt; &gt; to be SOLID here and we can&#39;t afford the 1024 limit.<br>
&gt; &gt;<br>
&gt; &gt; So... anyone interested? Any brilliant thoughts? AFAICT we can rest<br>
&gt; &gt; assured that there is a bug here somewhere, because otherwise we wouldn&#39;t<br>
&gt; &gt; be able to get &quot;errno 9 Bad file descriptor&quot;, right?<br>
&gt; &gt;<br>
</div></div>&gt; &gt; regards, G??ran<br>
<div class="HOEnZb"><div class="h5">&gt; &gt;<br>
&gt; &gt; PS. Googling this in relation to the Squeak VM didn&#39;t show any recent<br>
&gt; &gt; hits, only some from Stephen Pair fixing a bug in X11 code etc.<br>
&gt; &gt;<br>
&gt;<br>
&gt;<br>
&gt;<br>
&gt; --<br>
&gt; best,<br>
&gt; Eliot<br>
<br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br>best,<div>Eliot</div>
</div></div>