[Python-Dev] stdlib socket usage and "keepalive"

Jesus Cea jcea at jcea.es
Tue Apr 13 00:34:27 CEST 2010


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

On 04/13/2010 12:09 AM, Guido van Rossum wrote:
> Are you sure about this? ISTM that in most cases when a server goes
> away unexpectedly the local host will discover this when it next tries
> to use the socket. Also I recall reading that keepalives are a very
> controversial concept (since they may actually break connections
> unnecessarily if the internet merely has a hiccup).

The case is this:

1. The client does a request. Wait "read"ing the answer.

2. The request is "slow", so the server "acks" the TCP datagram and
start to process the request.

3. Now the connection is idle. The server is working and the client is
waiting, blocked in the socket "read()".

4. Now you switch off the server (or unplug the ethernet wire).

5. If the client kernel is not doing "keepalive", the client will be
blocked FOREVER (days), waiting for the reply. If the client uses
"keepalive", its kernel will send a probe after a while (30 minutes, for
instance), the probe will fail, and the kernel will shutdown the
connection. The problem is: linux doesn't uses KEEPALIVE by default.

I have validated this behaviour with Ubuntu 9.10 and a network sniffer.

About controversial... keepalive are usually sent only when the
connection is 100% idle for a while, when "while" can be >15 minutes, so
the load should be "none" for regular connections.

- -- 
Jesus Cea Avion                         _/_/      _/_/_/        _/_/_/
jcea at jcea.es - http://www.jcea.es/     _/_/    _/_/  _/_/    _/_/  _/_/
jabber / xmpp:jcea at jabber.org         _/_/    _/_/          _/_/_/_/_/
.                              _/_/  _/_/    _/_/          _/_/  _/_/
"Things are not so easy"      _/_/  _/_/    _/_/  _/_/    _/_/  _/_/
"My name is Dump, Core Dump"   _/_/_/        _/_/_/      _/_/  _/_/
"El amor es poner tu felicidad en la felicidad de otro" - Leibniz
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.9 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org/

iQCVAwUBS8Of85lgi5GaxT1NAQJaKwP+P9WvbWqmRyHRvNJFB2wLj87EanyOIN1e
TP646wUHJQtuU3XCyAWF53uM4rDGsbVh9j4TGK7+C1SHoRpPHlLMUdfwddtk8nK3
Owmo0V10sfHrFi1E0D5Ub/LXd1GG0ec7Q7OGN30nUR//hCuLe57ckEodwNQGzmtA
As5yJ5iwGFw=
=GOP1
-----END PGP SIGNATURE-----


More information about the Python-Dev mailing list