From: "Florian G. Pflug" Date: 2004-10-14T06:47:09+09:00 Subject: Re: ruby-mysql issues and persistence Andres Salomon wrote: >I have some code that triggers a race somewhere in mysql. Basically, what >happens is this (all in ruby code): > >1) using ruby-dbi w/ the mysql DBD, a connection is made to a database. >2) fork() is called >3) the child process redirects std{in,out,err} to /dev/null, and then runs >a SQL query; SET AUTOCOMMIT=1 >4) the child process runs another SQL query; this one is an INSERT. >5) the parent process exits. This exit calls all finalizers on objects in >the parent's memory, including free_mysql() (from mysql-ruby, free_mysql >is set as a callback inside init() via Data_Make_Struct()). free_mysql() >closes the mysql connection. >6) if timed correctly, the INSERT from step 4 hangs indefinitely. > > I don't think its a good idea to use the same database connection from two different processes. Either create a new connection for the child, or (if it absolutly _has_ to be the same connection) connect to some query-multiplexer from both processes. I guess what happens is that when the first process shuts down, it signals the mysql backend "end of connection". The backend thus believe the connection to be lost, and never reports a status back to the second process - thus it hangs forever, waiting for a sucess or failure message concerning the insert. greetings, Florian Pflug