From: George Wang Date: 2007-03-10T05:37:45+09:00 Subject: Re: Strange interference between LSAPI, popen3 and MySQL OK, we figured out what is wrong. "reopen" method need to be defined for "LSAPI" class since popen3 calls "reopen". LSAPI new release will address this. However, the root cause of broken MySQL connection is not LSAPI's fault, actually a bug in ruby's "open3.rb", the fix is like: def popen3(*cmd) pw = IO::pipe # pipe[0] for read, pipe[1] for write pr = IO::pipe pe = IO::pipe pid = fork{ # child fork{ # grandchild + begin pw[1].close STDIN.reopen(pw[0]) pw[0].close pr[0].close STDOUT.reopen(pr[1]) pr[1].close pe[0].close STDERR.reopen(pe[1]) pe[1].close exec(*cmd) + ensure + exit!(0) + end } exit!(0) } pw[0].close pr[1].close pe[1].close Process.waitpid(pid) pi = [pw[1], pr[0], pe[0]] pw[1].sync = true if defined? yield begin return yield(*pi) ensure pi.each{|p| p.close unless p.closed?} end end pi end module_function :popen3 end Whenever an error raise in the grandchild process, this process will not be terminated properly, and DB connection was closed in this process, thus the DB connection error in the main process. It happens to both mongrel and LSAPI. With above fix, DB connection is in good shape even without the LSAPI fix, just the command was not getting executed. Best Regards, George Wang http://www.litespeedtech.com/ -- Posted via http://www.ruby-forum.com/.