|
Home > Archive > Unix Programming > June 2004 > connection reset in proxy
You are viewing an archived Text-only version of the thread.
To view this thread in it's original format and/or if you want to reply to
this thread please [click here]
| Author |
connection reset in proxy
|
|
| Gopi Sundaram 2004-06-16, 5:57 pm |
| 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
| |
| David Schwartz 2004-06-16, 5:57 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
| |
| Gopi Sundaram 2004-06-17, 5:55 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;
}
| |
| David Schwartz 2004-06-17, 5:55 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
|
|
|
|
|