How does server handle clients that disconnect ungracefully?

Started by Jeff Lanzarottaalmost 19 years ago8 messagesgeneral
Jump to latest
#1Jeff Lanzarotta
delux256-postgresql@yahoo.com

Hello,

I am writing an application that reads information from my PostgreSQL
database. If I cause the program to crash and the program ends without
gracefully disconnecting from the database, there is an open connection
still left in the database.

How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this connection
that really is not there?

Thanks.

-Jeff

#2Magnus Hagander
magnus@hagander.net
In reply to: Jeff Lanzarotta (#1)
Re: How does server handle clients that disconnect ungracefully?

On Tue, Apr 24, 2007 at 05:53:02AM -0700, Jeff Lanzarotta wrote:

Hello,

I am writing an application that reads information from my PostgreSQL
database. If I cause the program to crash and the program ends without
gracefully disconnecting from the database, there is an open connection
still left in the database.

How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this connection
that really is not there?

Yes, but it will log a notice about it in the server log.

//Magnus

#3Richard Huxton
dev@archonet.com
In reply to: Jeff Lanzarotta (#1)
Re: How does server handle clients that disconnect ungracefully?

Jeff Lanzarotta wrote:

Hello,

I am writing an application that reads information from my PostgreSQL
database. If I cause the program to crash and the program ends without
gracefully disconnecting from the database, there is an open connection
still left in the database.

How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this connection
that really is not there?

Worst case is that the tcp/ip connection is never cleared down. That
means the connection will sit there until your tcp/ip stack clears it
down. I *think* that's an hour on linux.

--
Richard Huxton
Archonet Ltd

#4Jeff Lanzarotta
delux256-postgresql@yahoo.com
In reply to: Magnus Hagander (#2)
Re: How does server handle clients that disconnect ungracefully?

OK, thanks. I figured the server would at some point in time clear the
connection up, my question now is when does that happen? Any idea how
long the connection sit around before the server cleans it up? Someone
else said possibly an hour...

--- Magnus Hagander <magnus@hagander.net> wrote:
Show quoted text

On Tue, Apr 24, 2007 at 05:53:02AM -0700, Jeff Lanzarotta wrote:

Hello,

I am writing an application that reads information from my

PostgreSQL

database. If I cause the program to crash and the program ends

without

gracefully disconnecting from the database, there is an open

connection

still left in the database.

How does the PostgreSQL server handle clients that disconnect
ungracefully? Will the server automatically clean up this

connection

that really is not there?

Yes, but it will log a notice about it in the server log.

//Magnus

---------------------------(end of
broadcast)---------------------------
TIP 1: if posting/reading through Usenet, please send an appropriate
subscribe-nomail command to majordomo@postgresql.org so that
your
message can get through to the mailing list cleanly

#5Magnus Hagander
magnus@hagander.net
In reply to: Jeff Lanzarotta (#4)
Re: How does server handle clients that disconnect ungracefully?

On Tue, Apr 24, 2007 at 06:55:12AM -0700, Jeff Lanzarotta wrote:

OK, thanks. I figured the server would at some point in time clear the
connection up, my question now is when does that happen? Any idea how
long the connection sit around before the server cleans it up? Someone
else said possibly an hour...

Depends on yuor OS - when the TCP connection times out, PostgreSQL will
clean up and terminate the backup.

//Magnus

#6Jeff Lanzarotta
delux256-postgresql@yahoo.com
In reply to: Magnus Hagander (#5)
Re: How does server handle clients that disconnect ungracefully?

OK, that is what the other fellow said... It depends on the TCP/IP
stack...

Thanks again for the clarification.

--- Magnus Hagander <magnus@hagander.net> wrote:
Show quoted text

On Tue, Apr 24, 2007 at 06:55:12AM -0700, Jeff Lanzarotta wrote:

OK, thanks. I figured the server would at some point in time clear

the

connection up, my question now is when does that happen? Any idea

how

long the connection sit around before the server cleans it up?

Someone

else said possibly an hour...

Depends on yuor OS - when the TCP connection times out, PostgreSQL
will
clean up and terminate the backup.

//Magnus

---------------------------(end of
broadcast)---------------------------
TIP 6: explain analyze is your friend

#7Martijn van Oosterhout
kleptog@svana.org
In reply to: Jeff Lanzarotta (#6)
Re: How does server handle clients that disconnect ungracefully?

On Tue, Apr 24, 2007 at 07:16:38AM -0700, Jeff Lanzarotta wrote:

OK, that is what the other fellow said... It depends on the TCP/IP
stack...

Thanks again for the clarification.

Note, there are two cases. If only the program crashes but the system
is fine, the kernel will close the socket for you straight away and the
server with notice the hangup.

The only time the server will wait for a time out is if the server and
the client are on different machines and something disrupts actual
communications. If the client machine crashes without notifying the
server, or someone pulls out a network cable. If the client and the
server are on the same machine, it will always notice.

Have a nice day,
--
Martijn van Oosterhout <kleptog@svana.org> http://svana.org/kleptog/

Show quoted text

From each according to his ability. To each according to his ability to litigate.

#8Tom Lane
tgl@sss.pgh.pa.us
In reply to: Martijn van Oosterhout (#7)
Re: How does server handle clients that disconnect ungracefully?

Martijn van Oosterhout <kleptog@svana.org> writes:

The only time the server will wait for a time out is if the server and
the client are on different machines and something disrupts actual
communications.

Right, you need connectivity loss to create an issue --- a client
program crash doesn't cause this type of problem. The most common
form of the problem that I've heard about is routers deciding to drop a
connection that's been idle too long.

BTW, on some platforms it's possible to change the timeout settings so
that a lost connection is abandoned more quickly by the TCP stack.
See the tcp_keepalives_xxx parameters if you need to do that.

regards, tom lane