connection reset in proxy

  • Follow


I'm writing a proxy to a DB2 server in Perl. Here's what it does:

1) Open connection to DB2
2) Accept client connections
3) Fork. Parent goes back to accept.
4) Child handles client request, passes it to DB2, returns results to
   client, and quits.

It all works for the first client. When the second client makes a
request (after first has finished), the DBI barfs, saying "Communication
link failure, error code 73". errno 73 (on my system) is "Connection
reset by peer".

What's going on here? I just want the parent to set up the DB2
connection, and each child uses it in turn.

Any ideas, or suggestions of improvements/alternatives?

-- 
Gopi Sundaram
gopalan@cse.sc.edu
0
Reply Gopi 6/16/2004 8:32:30 PM

Gopi Sundaram wrote:

> I'm writing a proxy to a DB2 server in Perl. Here's what it does:
>
> 1) Open connection to DB2
> 2) Accept client connections
> 3) Fork. Parent goes back to accept.
> 4) Child handles client request, passes it to DB2, returns results to
>   client, and quits.
>
> It all works for the first client. When the second client makes a
> request (after first has finished), the DBI barfs, saying
> "Communication link failure, error code 73". errno 73 (on my system)
> is "Connection reset by peer".
>
> What's going on here? I just want the parent to set up the DB2
> connection, and each child uses it in turn.
>
> Any ideas, or suggestions of improvements/alternatives?

    There are millions of possible mistakes. Did you close the accepted 
connection in the parent? Did you close the listening socket in the child?

    DS


0
Reply David 6/16/2004 9:32:57 PM


On Wed, 16 Jun 2004, David Schwartz wrote:

> There are millions of possible mistakes. Did you close the accepted
> connection in the parent? Did you close the listening socket in the
> child?

Of course. My code follows below. The $dbh->prepare fails for the second
client, because it reports errno 73 for the connection to the DB2
server.

-------------------------------------------

# set up db2 connection with DBI handle $dbh

# setup socket here. socket(), bind(), listen(). note:
setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1);

while (1)
{
    my $address = accept(CLIENT, SERVER);
    # usual EINTR error checking here

    next if $pid = fork();

    # child continues here
    close(SERVER);

    # do stuff here with $dbh
    my $sth = $dbh->prepare("some SQL statement");
    $sth->execute();

    # print response to CLIENT. then
    close(CLIENT);
    exit(0);
}
continue
{
    # parent comes here from "next".
    close CLIENT;
}
0
Reply Gopi 6/16/2004 10:21:34 PM

Gopi Sundaram wrote:

> # set up db2 connection with DBI handle $dbh



> # setup socket here. socket(), bind(), listen(). note:
> setsockopt(SERVER, SOL_SOCKET, SO_REUSEADDR, 1);
>
> while (1)
> {
>    my $address = accept(CLIENT, SERVER);
>    # usual EINTR error checking here
>
>    next if $pid = fork();
>
>    # child continues here
>    close(SERVER);
>
>    # do stuff here with $dbh
>    my $sth = $dbh->prepare("some SQL statement");
>    $sth->execute();

    Here's your problem. When you finish the 'fork', both processes have the 
*SAME* db2 connection. When the first child uses that connection, its state 
changes and the next process to use it has no idea.

    DS


0
Reply David 6/17/2004 3:21:36 AM

3 Replies
563 Views

(page loaded in 0.082 seconds)

Similiar Articles:













7/23/2012 7:57:16 AM


Reply: