<html><head></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space; ">Hi Guys,<div><br></div><div>I'm working on some integration project with Ruby, Rack, Apache, Phusion Passenger and Xapian.</div><div><br></div><div>I've been having intermittent issues with the flintlock code - it seems that the function FlintLock::lock is never returning and this is locking up the Ruby process.</div><div><br></div><div>My guess is that Xapian is locking up in a system call and Ruby can't schedule its green threads.</div><div><br></div><div>I've done some basic debugging with strace and noticed the following:</div><div><br></div><div><div>29944 30022 29942 29939 ? -1 Sl 33 0:09 | | \_ Passenger ApplicationSpawner: /srv/www/www.oriontransfer.co.nz </div><div>30022 30041 29942 29939 ? -1 S 33 0:00 | | | \_ /bin/cat </div></div><div><br></div><div>[Using the following source code as a reference <a href="http://xapian.org/docs/sourcedoc/html/flint__lock_8cc_source.html]">http://xapian.org/docs/sourcedoc/html/flint__lock_8cc_source.html]</a></div><div><br></div><div>At this point, using strace I found that the application process seemed to be stuck in on</div><div><span class="Apple-style-span" style="font-family: monospace, fixed; font-size: 13px; "><pre class="fragment" style="font-family: monospace, fixed; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(245, 245, 245); padding-top: 4px; padding-right: 6px; padding-bottom: 4px; padding-left: 6px; margin-top: 4px; margin-right: 8px; margin-bottom: 4px; margin-left: 2px; position: static; z-index: auto; ">00219 ssize_t n = read(fds[0], &ch, 1);</pre></span><div><br></div></div><div>Obviously child process was cat, nothing really interesting about that.</div><div><br></div><div>After I killed cat, then the process was freed up and the web application started responding again.</div><div><br></div><div>Well, I don't know why this is unreliable I've briefly looked at the code and noticed a few things:</div><div><br></div><div><span class="Apple-style-span" style="font-family: monospace, fixed; font-size: 13px; "><pre class="fragment" style="font-family: monospace, fixed; font-size: 13px; border-top-width: 1px; border-right-width: 1px; border-bottom-width: 1px; border-left-width: 1px; border-top-style: solid; border-right-style: solid; border-bottom-style: solid; border-left-style: solid; border-top-color: rgb(204, 204, 204); border-right-color: rgb(204, 204, 204); border-bottom-color: rgb(204, 204, 204); border-left-color: rgb(204, 204, 204); background-color: rgb(245, 245, 245); padding-top: 4px; padding-right: 6px; padding-bottom: 4px; padding-left: 6px; margin-top: 4px; margin-right: 8px; margin-bottom: 4px; margin-left: 2px; ">00172 <span class="comment" style="color: rgb(128, 0, 0); ">// Connect pipe to stdin and stdout.</span>
<a name="l00173" style="color: rgb(21, 55, 136); font-weight: normal; text-decoration: none; "></a>00173 dup2(fds[1], 0);
<a name="l00174" style="color: rgb(21, 55, 136); font-weight: normal; text-decoration: none; "></a>00174 dup2(fds[1], 1);</pre></span><div><br></div></div><div>Isn't this setting stdin and stdout to the same end of an existing pipe? Does this make sense?</div><div><br></div><div>Anyway, I thought I'd mention this because it is a consistent problem. If there is anything you think I should do with strace, gdb, etc on the processes next time it hangs, let me know.</div><div><br></div><div>One option to fix the bug without really understanding the real issue would be to use select in the parent thread, rather than read. Then, use a timeout of a few seconds so that if the child doesn't acquire the lock within x seconds, it is as good as failed.</div><div><br></div><div>Kind regards,</div><div>Samuel</div><div><br></div><div><br></div></body></html>