D
Daniel DeLorme
It's commonly known that database connections do not play well with
Process.fork; I thought that using at_exit{exit!} was the correct way
to solve this problem, but it appears imperfect. Take this pseudo-code:
1 db1 = mysql_connect()
2 Process.fork do
3 at_exit{exit!}
4 db2 = mysql_connect()
5 db2.query(...)
6 end
7 Process.wait
8 db1.query(...)
With line 3, only the at_exit handlers defined in the child process are
run when the child exits, ensuring that db1 stays alive and line 8 keeps
working.
At least that's what I thought. But in the past 2 days I've been getting
some "MySQL server has gone away" errors from our servers, indicating
that at_exit{exit!} is not enough to protect the db1 connection. It's
not consistently reproducible; I can't get the error when directly
testing but the flow of errormails is unmistakable. So what exactly
was wrong in my understanding of at_exit, sockets, mysql, and fork?
-Daniel
Process.fork; I thought that using at_exit{exit!} was the correct way
to solve this problem, but it appears imperfect. Take this pseudo-code:
1 db1 = mysql_connect()
2 Process.fork do
3 at_exit{exit!}
4 db2 = mysql_connect()
5 db2.query(...)
6 end
7 Process.wait
8 db1.query(...)
With line 3, only the at_exit handlers defined in the child process are
run when the child exits, ensuring that db1 stays alive and line 8 keeps
working.
At least that's what I thought. But in the past 2 days I've been getting
some "MySQL server has gone away" errors from our servers, indicating
that at_exit{exit!} is not enough to protect the db1 connection. It's
not consistently reproducible; I can't get the error when directly
testing but the flow of errormails is unmistakable. So what exactly
was wrong in my understanding of at_exit, sockets, mysql, and fork?
-Daniel