Add timeouts to smart transport protocol clients
commit61645b938bc934fda3b0624c5bac1e3495634750
authorShawn O. Pearce <spearce@spearce.org>
Fri, 19 Jun 2009 21:27:52 +0000 (19 14:27 -0700)
committerRobin Rosenberg <robin.rosenberg@dewire.com>
Tue, 23 Jun 2009 22:16:55 +0000 (24 00:16 +0200)
tree55196bcafcd56fe5586c7b1dfc6cd70b767d5afc
parent20e38f86a22a01d6048508aa3f7ccb2bab1c9a10
Add timeouts to smart transport protocol clients

For both directions (input and output) we start a background thread
to interrupt the main processing thread if a read or write event on
the low-level stream does not complete in the configured timeout.
On timeout, we abort the transaction entirely.  Any sort of short
read or write doesn't need to be handled.

JSch made a timeout on write difficult because they explicitly do
a catch for InterruptedException inside of their OutputStream.  We
have to work around that by creating an additional thread that just
shuttles data between our own OutputStream and the real JSch stream.
Our OutputStream can be interrupted, which causes it to close, which
in turn closes the JSch Channel and Session.  That breaks our little
copy thread out of the JSch OutputStream, letting it terminate.  Its
not pretty, but its the best we can do with current versions of JSch.

During a push receive-pack stalls while it processes the deltas in
the received data and indexes the new pack on disk, or unpacks the
data into loose objects.  During this stall we receive no network
transfer from the remote side, so we cannot know if the peer has
deadlocked with us, or is progressing normally.  Since the time is
usually proportional to the data sent we give the remote side up to
10x the time we spent transmitting data, or our configured timeout,
hoping it will be able to complete and return a pack success or fail
status report before we timeout.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
Signed-off-by: Robin Rosenberg <robin.rosenberg@dewire.com>
org.spearce.jgit/src/org/spearce/jgit/transport/BasePackConnection.java
org.spearce.jgit/src/org/spearce/jgit/transport/BasePackPushConnection.java
org.spearce.jgit/src/org/spearce/jgit/transport/SshTransport.java
org.spearce.jgit/src/org/spearce/jgit/transport/Transport.java
org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitAnon.java
org.spearce.jgit/src/org/spearce/jgit/transport/TransportGitSsh.java
org.spearce.jgit/src/org/spearce/jgit/transport/TransportLocal.java
org.spearce.jgit/src/org/spearce/jgit/transport/TransportSftp.java