{"id":688,"date":"2008-11-18T15:25:43","date_gmt":"2008-11-18T20:25:43","guid":{"rendered":"http:\/\/nuxx.net\/blog\/?p=688"},"modified":"2008-11-20T17:06:39","modified_gmt":"2008-11-20T22:06:39","slug":"php-cgi-hung-as-sbwait-with-lighttpd-on-freebsd","status":"publish","type":"post","link":"https:\/\/nuxx.net\/blog\/2008\/11\/18\/php-cgi-hung-as-sbwait-with-lighttpd-on-freebsd\/","title":{"rendered":"php-cgi hung as sbwait with lighttpd on FreeBSD"},"content":{"rendered":"<p><center><\/p>\n<table cellpadding=1>\n<tr>\n<td bgcolor=\"black\"><img decoding=\"async\" src=\"https:\/\/nuxx.net\/gallery\/d\/77797-2\/gallery_remote_hang.png\" height=215 width=396 border=0 alt=\"Gallery Remote hung at &quot;Upload completed: server processing...&quot;, which is the most obvious symptom of the lighttpd \/ php-cgi problems I've been having.\"><\/td>\n<\/tr>\n<\/table>\n<p><\/center><\/p>\n<p>When uploading a quantity of photos to <a href=\"https:\/\/nuxx.net\/gallery\">my gallery<\/a> I like to use a tool like <a href=\"http:\/\/gallery.menalto.com\/wiki\/Gallery_Remote\">Gallery Remote<\/a> to make it go easier. However, since moving to <a href=\"https:\/\/nuxx.net\/gallery\/v\/computers\/banstyle_nuxx_net\/\">banstyle<\/a> (and a newer version of <a href=\"http:\/\/www.freebsd.org\/\">FreeBSD<\/a> and <a href=\"http:\/\/www.lighttpd.net\/\">lighttpd<\/a> and <a href=\"http:\/\/www.php.net\">PHP<\/a>) I&#8217;ve had Gallery Remote regularly hang at that &#8220;Upload completed: server processing&#8230;&#8221; message. It seems to happen after a few (typically two to five) images have been uploaded.<\/p>\n<p>This problem has been bothering me for a while, but I was able to work around it by <tt>scp<\/tt>ing the files to the server then adding them locally, which doesn&#8217;t have this problem. Now that I have a bunch of photos from the UK trip to upload, I want to be able to use Gallery Remote again. This morning I set to getting working, but I seem to have failed.<\/p>\n<p>In short, what happens is that after an upload hangs I see one of the <tt>php-cgi<\/tt> processes stuck in a status of <tt>sbwait<\/tt>, as can be seen in <a href=\"https:\/\/nuxx.net\/gallery\/v\/computers\/screenshots\/top_on_banstyle_sbwait_php-cgi.png.html?g2_imageViewsIndex=2\">this screenshot<\/a>:<\/p>\n<blockquote><p><tt>81073&nbsp;c0nsumer&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;1&nbsp;&nbsp;&nbsp;4&nbsp;&nbsp;&nbsp;&nbsp;0&nbsp;&nbsp;&nbsp;116M&nbsp;20988K&nbsp;sbwait&nbsp;3&nbsp;&nbsp;&nbsp;0:01&nbsp;&nbsp;0.00%&nbsp;php-cgi<\/tt><\/p><\/blockquote>\n<p>Digging around I found <a href=\"http:\/\/lists.freebsd.org\/pipermail\/freebsd-stable\/2008-November\/046432.html\">this thread<\/a> where someone else indicates that they are having the same problem, and only on SMP boxes. (Note: banstyle.nuxx.net is four-way SMP using SCHED_ULE.) I also came across <a href=\"http:\/\/redmine.lighttpd.net\/boards\/2\/topics\/show\/141\">this report<\/a> to the lighttpd folks regarding this issue. The consensus seems to be that when using a config such as mine, with PHP as a <a href=\"http:\/\/www.fastcgi.com\">FastCGI<\/a> and lighttpd, this occasionally happens. I&#8217;ve seen no reports of the issue occurring under Apache.<\/p>\n<p>Since I&#8217;m able to reproduce the problem I did so, attached <a href=\"http:\/\/www.gnu.org\/software\/gdb\/\">gdb<\/a> to the seemingly hung <tt>php-cgi<\/tt> process, and grabbed a <a href=\"http:\/\/en.wikipedia.org\/wiki\/Stack_trace\">backtrace<\/a>:<\/p>\n<blockquote><p><tt>(gdb)&nbsp;bt<\/tt><br \/>\n<tt>#0&nbsp;&nbsp;0x00000008010a476a&nbsp;in&nbsp;read&nbsp;()&nbsp;from&nbsp;\/lib\/libc.so.7<\/tt><br \/>\n<tt>#1&nbsp;&nbsp;0x000000000057d5fc&nbsp;in&nbsp;fcgi_read&nbsp;()<\/tt><br \/>\n<tt>#2&nbsp;&nbsp;0x000000000057e306&nbsp;in&nbsp;sapi_cgi_read_post&nbsp;()<\/tt><br \/>\n<tt>#3&nbsp;&nbsp;0x00000000004c84a4&nbsp;in&nbsp;fill_buffer&nbsp;()<\/tt><br \/>\n<tt>#4&nbsp;&nbsp;0x00000000004c88b5&nbsp;in&nbsp;multipart_buffer_read&nbsp;()<\/tt><br \/>\n<tt>#5&nbsp;&nbsp;0x00000000004c9c08&nbsp;in&nbsp;rfc1867_post_handler&nbsp;()<\/tt><br \/>\n<tt>#6&nbsp;&nbsp;0x00000000004c6ee5&nbsp;in&nbsp;sapi_handle_post&nbsp;()<\/tt><br \/>\n<tt>#7&nbsp;&nbsp;0x00000000004cc30c&nbsp;in&nbsp;php_default_treat_data&nbsp;()<\/tt><br \/>\n<tt>#8&nbsp;&nbsp;0x00000000004cc7eb&nbsp;in&nbsp;php_hash_environment&nbsp;()<\/tt><br \/>\n<tt>#9&nbsp;&nbsp;0x00000000004bff47&nbsp;in&nbsp;php_request_startup&nbsp;()<\/tt><br \/>\n<tt>#10&nbsp;0x000000000057f8c6&nbsp;in&nbsp;main&nbsp;()<\/tt><\/p>\n<p><tt>(gdb)&nbsp;f&nbsp;0<\/tt><br \/>\n<tt>#0&nbsp;&nbsp;0x00000008010a476a&nbsp;in&nbsp;read&nbsp;()&nbsp;from&nbsp;\/lib\/libc.so.7<\/tt><br \/>\n<tt>(gdb)&nbsp;info&nbsp;frame<\/tt><br \/>\n<tt>Stack&nbsp;level&nbsp;0,&nbsp;frame&nbsp;at&nbsp;0x7fffffff9c50:<\/tt><br \/>\n<tt>&nbsp;rip&nbsp;=&nbsp;0x8010a476a&nbsp;in&nbsp;read;&nbsp;saved&nbsp;rip&nbsp;0x57d5fc<\/tt><br \/>\n<tt>&nbsp;called&nbsp;by&nbsp;frame&nbsp;at&nbsp;0x7fffffff9db0<\/tt><br \/>\n<tt>&nbsp;Arglist&nbsp;at&nbsp;0x7fffffff9c40,&nbsp;args:&nbsp;<\/tt><br \/>\n<tt>&nbsp;Locals&nbsp;at&nbsp;0x7fffffff9c40,&nbsp;Previous&nbsp;frame's&nbsp;sp&nbsp;is&nbsp;0x7fffffff9c50<\/tt><br \/>\n<tt>&nbsp;Saved&nbsp;registers:<\/tt><br \/>\n<tt>&nbsp;&nbsp;rip&nbsp;at&nbsp;0x7fffffff9c48<\/tt><\/p><\/blockquote>\n<p>Based on the input from some folks online, it&#8217;s looking like that is <tt>php-cgi<\/tt> doing what it&#8217;s supposed to and just waiting for more data, which means that the problem is likely somewhere in lighttpd. I&#8217;m not really sure where to go from here, besides wait for the lighttpd folks to (hopefully) fix the problem. With any luck I&#8217;ll be able to update this post later on with a solution. For now I&#8217;m going to contemplate the difficulty of going (back, in many ways) to Apache.<\/p>\n<p>For reference, I&#8217;m running lighttpd 1.4.20 and PHP 5.2.6, both installed from <a href=\"\">ports<\/a>, configured as described in <a href=\"https:\/\/nuxx.net\/wiki\/lighttpd\">my article about running lighttpd with PHP as FastCGI with each user having their own PHP processes<\/a>.<\/p>\n<p><strong>UPDATE:<\/strong> So, it seems that there is a fix for this which was suggested in <a href=\"http:\/\/redmine.lighttpd.net\/boards\/2\/topics\/show\/141\">the aforementioned bug report<\/a>. Setting the option <tt>server.network-backend = \"writev\"<\/tt> along with the already set (in my case) <tt>server.event-handler = \"freebsd-kqueue\"<\/tt> in lighttpd fixes it. I&#8217;m not sure if both options are needed to resolve the issue, but it seems that the default setting for <tt>server.network-backend<\/tt> of <tt>write<\/tt> is confirmed as broken under FreeBSD 7.0-RELEASE with lighttpd <= 1.4.20.\n<\/p>\n","protected":false},"excerpt":{"rendered":"<p>When uploading a quantity of photos to my gallery I like to use a tool like Gallery Remote to make it go easier. However, since&#8230;<\/p>\n<div class=\"more-link-wrapper\"><a class=\"more-link\" href=\"https:\/\/nuxx.net\/blog\/2008\/11\/18\/php-cgi-hung-as-sbwait-with-lighttpd-on-freebsd\/\">Continue reading<span class=\"screen-reader-text\">php-cgi hung as sbwait with lighttpd on FreeBSD<\/span><\/a><\/div>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,4],"tags":[],"class_list":["post-688","post","type-post","status-publish","format-standard","hentry","category-computers","category-nuxxnet","entry"],"amp_enabled":true,"_links":{"self":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/688","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/comments?post=688"}],"version-history":[{"count":11,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/688\/revisions"}],"predecessor-version":[{"id":718,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/posts\/688\/revisions\/718"}],"wp:attachment":[{"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/media?parent=688"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/categories?post=688"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/nuxx.net\/blog\/wp-json\/wp\/v2\/tags?post=688"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}