E
Eric Schwartz
The following script reliably gives me a DBI:atabaseError
$ 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
$ /tmp/test.rb
/usr/lib/ruby/1.8/DBD/Mysql/Mysql.rb:403:in `execute': Lost connection to MySQL server during query (DBI:atabaseError)
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. That does NOT seem to be the case, however, as if I
change the exec() to
exec('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?
-=Eric
$ 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
$ /tmp/test.rb
/usr/lib/ruby/1.8/DBD/Mysql/Mysql.rb:403:in `execute': Lost connection to MySQL server during query (DBI:atabaseError)
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. That does NOT seem to be the case, however, as if I
change the exec() to
exec('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?
-=Eric