Subject: Re: Trying to understand keepalive

Re: Trying to understand keepalive

From: Henrik Nordström <henrik_at_henriknordstrom.net>
Date: Sun, 25 Dec 2011 12:58:34 +0100

sön 2011-12-25 klockan 03:09 +0100 skrev Fritz Elfert:

> Studying the source of libssh2 (current git), I noticed, that while
> libssh2 supports sending keepalive messages as well as replying to
> keepalives sent from the server, it apparently does *not* act on the
> responses from the server even when want_reply is set while invoking
> libssh2_keepalive_send().

The keep-alive implementation in libssh2 is very rudimentary, and not
without problems. Currently it helps keeping an idle connection alive,
but not good for detecting communication issues, and may even cause
additional communication issues if EAGAIN is seen when sending the
keep-alive message.
 
> So am I missing something here?
> Or: How am I (as a user of libssh2) supposed to find out, if the server
> has properly responded to the keepalive that I just sent?

From what I can tell you can't.

There really should be timestamps recording time of last sent, last sent
with want_reply set and last received packet, and keepalive adjusted to
monitor these both for determining if keep-alive is needed and for
detecting session timeout. Technically just one of the last sent
timestamps is sufficient, but to keep the logics of which time to track
for keep-alive isolated within keepalive it's easier if both are
recorded in the session.

It's not really important to track if the received (or sent) packets are
in reply to keep-alive or not. It's sufficient to note that there is
traffic.

I don't know why ticket #183 was closed (Daniel?). Does not look
outdated to me. May even work to some degree. But needs to be improved
slightly to handle want_reply == 0 without timing out the session, and
do not solve a couple of other keep-alive issues.

Regards
Henrik

_______________________________________________
libssh2-devel http://cool.haxx.se/cgi-bin/mailman/listinfo/libssh2-devel
Received on 2011-12-25