CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
Search Posts SEARCH
Who's Online WHO'S
Log in LOG

Home: Perl Programming Help: DBI:
DB Connections resetting


New User

Nov 20, 2009, 1:59 AM

Post #1 of 2 (7598 views)
DB Connections resetting Can't Post

I have a perl daemon script which gets data from DB and for each row forks a child process which will make a web service request. My script ensures that the number of forks will never be greater than 5.
Both the parent and child processes uses Rose:: DB:: Object connection to access and update mysql db.
During the execution, the parent process database connection is getting reset.

process_webservice stopped get_objects() - DBD::mysql::st execute failed: Lost connection to MySQL server during query at /home/perl/5.8/Rose/DB/Object/

Any pointers on how to resolve this issue ?


Nov 24, 2009, 8:14 AM

Post #2 of 2 (7430 views)
Re: [vmraj] DB Connections resetting [In reply to] Can't Post

Hi vmraj,

Caveats: I have never used Rose::DB::Object and anyway, I haven't seen your code, but...

Are you opening your db with Rose::DB->new_or_cached()? If so, your parent may be sharing the same db session with the children even though they supposedly have their own database objects.

Another (related) possiblity is that you're forking the child after you connect to the db in the parent. I suspect the following sequence of events might be occurring:

1. The child gets a copy of the parent's heap during the fork.
2. The child's heap includes a copy of the parent's Rose::DB::Object (with associated db handle).
3. The child destroy's it's copy of the parent's db object upon exit and the Rose::DB library closes the db session.
4. Meanwhile, in the parent, it's db handle has just been invalidated because the child closed the session.

If this is happening, you'll have to re-open the db in the parent after each fork or use something like Rose::DB::AutoReconnect.


If the parent doesn't have to interact with the db too often, perhaps the easiest thing to do would be to open a new session for each transaction.



(This post was edited by 1arryb on Nov 25, 2009, 7:46 AM)


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives