>> I am experiencing a very strange problem in my Rails app. I use popen3
>> to execute an external program. Everything works fine in Mongrel, but
>> when I use the app with LSAPI, after popen3 all MySQL queries fail with
>> "Mysql::Error (MySQL server has gone away)". Once I comment out popen3
>> it works fine again.
>>
>> Does anyone have the slightest idea about what goes wrong here?
> 
> guessing, but popen3 uses fork.  forking with and open db handle is undefined
> for almost any db lib - of course people ignore this.  i did, and had all
> sorts of issues.  you can read about them here

OK, good to know. I can close the MySQL connection for the popen3 call 
and reopen it after it to avoid problems.

> i bet what happens is that the parent (rails) has setup an at_exit handler to
> close the db on exit.

That makes sense, although I couldn't find any reference to at_exit in 
Rails or ruby-lsapi.

> i'd try putting this
> 
> 
>    class Object
>      alias_method '__fork__', 'fork'
>      def fork *a, &b
>        at_exit{ exit! }
>        __fork__ *a, &b
>      end
>    end
>    module Kernel
>      alias_method '__fork__', 'fork'
>      def fork *a, &b
>        at_exit{ exit! }
>        __fork__ *a, &b
>      end
>    end
> 
> in environment.rb or something.

This fixes the MySQL problem (as does manually 
disconnecting/reconnecting), but now I have another problem: popen3 just 
doesn't do anything when used within LSAPI. The program is never 
executed. Any ideas?

Who would have thought that simply calling an external program could be 
so difficult...

Thanks
Andreas

-- 
Posted via http://www.ruby-forum.com/.