Another note...
"Eric Schwartz" <emschwar@pobox.com> schrieb im Newsbeitrag
news:etoy8jck980.fsf@wilson.emschwar...
The following script reliably gives me a DBI::DatabaseError
$ cat /tmp/test.rb
#!/usr/bin/ruby
require 'dbi'dbh = DBI.connect("DBI:mysql:host=test.test;db=test", "test", "test")
fork {
fork {
$stderr.close
$stdout.close
$stdin.close
exec("/bin/ls >/dev/null 2>&1")
}
}
sth = dbh.prepare("select * from machines")
sth.execute
Another reason might be the fork after the DBI.connect() - the child might
close the connection on exit. I'd move the DBI.connect to the line
directly prepending "sth = ...".
$ /tmp/test.rb
/usr/lib/ruby/1.8/DBD/Mysql/Mysql.rb:403:in `execute': Lost connection
to MySQL server during query (DBI::DatabaseError)
from /usr/lib/ruby/1.8/dbi/dbi.rb:769:in `execute'
from /tmp/test.rb:11
$The context this problem came from is: I have a CGI program that must
fire off a long-running process. I want to use the standard Unix
double-fork trick to allow the long-running process to detach itself
and run independently. My first thought was that if there's an error
in the child process, it exits first, and closes the DBI connection
automatically.
Maybe it closes the connection on startup. Since your child process
doesn't seem to need the connection I'd create it immediately before I use
it.
That does NOT seem to be the case, however, as if I
change the exec() toexec('sleep 20; /bin/ls >/dev/null 2>&1')
then I still get the Lost connection error. What causes this, and are
there standard patterns for fixing it?
See above.
Kind regards
robert