----- Original Message ----- From: "Mark" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]> Sent: Monday, December 23, 2002 3:13 PM Subject: What is wrong with this query?
> For month now I have been plagued by the "Lost connection to MySQ > server during query" in a Perl program of mine that connects locally to > /tmp/mysql.sock. Dear folks, At long last I found the cause of this nagging problem; it had nothing to do with MySQL, but with Perl. The cause is so bizarre, that I feel other people may benefit from my solution. If not, it makes for an interesting story. :) Ok, her goes. My own Perl news server, like any other daemon, daemonizes at some point; like so: chdir ('/') || exit 1; open STDIN, '/dev/null'; open STDOUT, '>/dev/null'; if (my $pid = fork ()) { open (USERLOG, ">".'/var/run/news.pid') || exit 1; flock (USERLOG, 2); seek (USERLOG, 0, 0); print USERLOG " $pid"; close (USERLOG); system ("/usr/sbin/chown news:news /var/run/news.pid"); exit 0; } POSIX::setsid () || exit 1; Etc. It is hard to spot, but the culprit was already in this block of code: the system call to "chown". Literally having taken the program apart, line by line, I found out, to my astonishment, that when I remove the "chown" line, that then everything remains stable. If I leave it in, I get the imfamous "Lost connection to MySQL server during query" within seconds; or, at least, very regularly. I solved this by adding a "sleep 5" after the chown command, and before the "exit 0". For reasons beyond my grasp, having the parent wait an extra 5 seconds, while the child does its start-up stuff, makes all the difference. I do not understand why. It seems that the parent exit-ing while the child is doing stuff, makes the child lose its query to MySQL (always more or less at the same point). And this is really strange; for the parent has nothing to do with MySQL. It is the child who makes the connection and does all queries. So, having the parent linger a bit should have no affect on the child. Yet it does. It may be that the extra system shell, before the parent exists, interferes with the child upon exit. But I cannot see how (perhaps STDIN and STDOUT get rearranged?). Still, adding a "sleep 5" after the parent system call solves all the problems. Permanently. Just did a loop-test; 100 out of a 100 start-ups went ok. Remove the "sleep 5", and the child goes haywire again. Perhaps this is trivial to you. In that case, more power to you! But it was not trivial to me. It took me months to figure this one out. And so we learn. :) - Mark --------------------------------------------------------------------- Before posting, please check: http://www.mysql.com/manual.php (the manual) http://lists.mysql.com/ (the list archive) To request this thread, e-mail <[EMAIL PROTECTED]> To unsubscribe, e-mail <[EMAIL PROTECTED]> Trouble unsubscribing? Try: http://lists.mysql.com/php/unsubscribe.php