Michael Peppler
Sybase Consulting
Sybase on Linux
Install Guide for Sybase on Linux
General Sybase Resources
General Perl Resources
BCP Tool
Bug Tracker
Mailing List Archive
Downloads Directory
Sybase on Linux FAQ
Sybperl FAQ
Michael Peppler's resume

sybperl-l Archive

Up    Prev    Next    

From: Tim_Green at mercer dot com
Subject: Re: Passing a connection across a fork ()
Date: Feb 23 1998 3:29PM

>In order to handle multiple requests simultaneously, I fork off a child 
>process to each request and pass it the connection to the database.  In 
>otherwords, I have multiple processes using the same connection.  
>Everything works fine unless one of the children is killed.  That kills 
>the connections to the database for all of the processes.  The problem 
>seems to be that the child closes the database connection when it dies. 
> The error message that the other children get is to the effect that 
>the database connection has been closed.
>My questions are:
>1) Is is safe to pass a database connection through a fork or am I just 
     getting lucky?  
     Are you sure the error is that the connection is closed, or is it 
     possible that the child that was killed didn't process all the results 
     left on the connection?  How are you assuring that the children don't 
     attempt to use the connection simultaneously?
>The alternatives are
>- to open a number of database connections and give one to each child 
>  (though this assumes that passing a connection through a fork is 
>  allowed)

     We do something similar here, using Sybperl's DBlib module, but have 
     not run into the problems that you mention.  Our daemon process 
     maintains an administrative connection to the server.  When a request 
     comes through it establishes another connection to the database for 
     the child process and then forks.  The child process then uses the new 
     connection until it terminates.  Upon termination (which can be normal 
     completion or by it being killed), the server then uses the connection 
     that it gave to the child to do some clean up, and then closes it.  We 
     have not experienced a problem with either the server's administrative 
     connection or the child connections when a child process is killed, 
     and we actually give our users the ability to kill their child 
     processes through our front end, and they use it quite a bit.
     I have heard others mention problems even with this approach.  Not 
     knowing enough about writing multithreaded applications (this server 
     was my first), I'm not sure whether I was just lucky or not.  Perhaps 
     your problems (or my success ) are related to the software 
     versions being used.  We're running perl 5.003, Sybperl 2.05 and Open 
     Client 10.0.4.
     Good luck,
     Tim Green                               
     Administrative Solutions Group
     "An ADP/Mercer Alliance"