[Twisted-Python] connectionLost not always getting called?

Jean-Paul Calderone exarkun at divmod.com
Sun Jan 11 20:27:19 EST 2009

On Sun, 11 Jan 2009 15:55:03 -0800, Rob Bredow <rob at 185vfx.com> wrote:
>I've implemented a twisted server using the basic.lineReceiver class.  The
>client is a socket based client implemented in flash and the connections are
>long-lived (minutes or hours).  To handle cleaning up the players when they
>disconnect, I'm using the connectionLost function in my player class.  99%
>of the time, things work as expected.
>However in rare cases, connectionLost is not getting called when the
>flash-based client disappears.  Even completely quitting the client's
>web-browser does not always trigger a connectionLost call.  I tracked down
>one specific instance yesterday where the server thought the client was
>still connected even though the client had been gone for 30+ minutes--but
>after a few hours the server noticed that the client was gone and then
>connectionLost was called like normal.  That made me think that it might be
>a problem on the server side and maybe not client related.
>I'm starting on a workaround now where the client will issue a "PING" every
>30 seconds and the server will use the ping information to manually trigger
>loseConnection when needed.  Are there a better workarounds for this, better
>practices or some error checking I can do to avoid these intermidant laggy
>connectionLost calls?

This is a FAQ, so I've just added it to the FAQ.  Please let me know what
you think of the entry:



More information about the Twisted-Python mailing list