From: "Shawn O. Pearce" <spearce@spearce.org>
To: Robin Rosenberg <robin.rosenberg@dewire.com>
Cc: git@vger.kernel.org
Subject: [JGIT PATCH 5/6] Add timeouts to anonymous git:// daemon
Date: Fri, 19 Jun 2009 14:27:54 -0700 [thread overview]
Message-ID: <1245446875-31102-6-git-send-email-spearce@spearce.org> (raw)
In-Reply-To: <1245446875-31102-5-git-send-email-spearce@spearce.org>
If the initial command line isn't received within the configured
timeout period, the connection is dropped, and the service thread
is able to terminate.
The timeout is also pushed down to the service implementations,
so they can abort if the client doesn't speak to them within the
configured time span.
Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
.../src/org/spearce/jgit/transport/Daemon.java | 26 ++++++++++++++++---
.../org/spearce/jgit/transport/DaemonClient.java | 12 +++++++--
2 files changed, 31 insertions(+), 7 deletions(-)
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java b/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
index be27732..3101d6f 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/Daemon.java
@@ -37,8 +37,6 @@
package org.spearce.jgit.transport;
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
@@ -79,6 +77,8 @@
private Thread acceptThread;
+ private int timeout;
+
/** Configure a daemon to listen on any available network port. */
public Daemon() {
this(null);
@@ -108,6 +108,7 @@ protected void execute(final DaemonClient dc,
final Repository db) throws IOException {
final UploadPack rp = new UploadPack(db);
final InputStream in = dc.getInputStream();
+ rp.setTimeout(Daemon.this.getTimeout());
rp.upload(in, dc.getOutputStream(), null);
}
}, new DaemonService("receive-pack", "receivepack") {
@@ -127,6 +128,7 @@ protected void execute(final DaemonClient dc,
final String name = "anonymous";
final String email = name + "@" + host;
rp.setRefLogIdent(new PersonIdent(name, email));
+ rp.setTimeout(Daemon.this.getTimeout());
rp.receive(in, dc.getOutputStream(), null);
}
} };
@@ -213,6 +215,23 @@ synchronized (exportBase) {
}
}
+ /** @return timeout (in seconds) before aborting an IO operation. */
+ public int getTimeout() {
+ return timeout;
+ }
+
+ /**
+ * Set the timeout before willing to abort an IO call.
+ *
+ * @param seconds
+ * number of seconds to wait (with no data transfer occurring)
+ * before aborting an IO read or write operation with the
+ * connected client.
+ */
+ public void setTimeout(final int seconds) {
+ timeout = seconds;
+ }
+
/**
* Start this daemon on a background thread.
*
@@ -280,8 +299,7 @@ private void startClient(final Socket s) {
new Thread(processors, "Git-Daemon-Client " + peer.toString()) {
public void run() {
try {
- dc.execute(new BufferedInputStream(s.getInputStream()),
- new BufferedOutputStream(s.getOutputStream()));
+ dc.execute(s);
} catch (IOException e) {
// Ignore unexpected IO exceptions from clients
e.printStackTrace();
diff --git a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java
index e80d86b..52b2ae0 100644
--- a/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java
+++ b/org.spearce.jgit/src/org/spearce/jgit/transport/DaemonClient.java
@@ -37,10 +37,13 @@
package org.spearce.jgit.transport;
+import java.io.BufferedInputStream;
+import java.io.BufferedOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.net.InetAddress;
+import java.net.Socket;
/** Active network client of {@link Daemon}. */
public class DaemonClient {
@@ -80,11 +83,13 @@ public OutputStream getOutputStream() {
return rawOut;
}
- void execute(final InputStream in, final OutputStream out)
+ void execute(final Socket sock)
throws IOException {
- rawIn = in;
- rawOut = out;
+ rawIn = new BufferedInputStream(sock.getInputStream());
+ rawOut = new BufferedOutputStream(sock.getOutputStream());
+ if (0 < daemon.getTimeout())
+ sock.setSoTimeout(daemon.getTimeout() * 1000);
String cmd = new PacketLineIn(rawIn).readStringRaw();
final int nul = cmd.indexOf('\0');
if (nul >= 0) {
@@ -98,6 +103,7 @@ void execute(final InputStream in, final OutputStream out)
final DaemonService srv = getDaemon().matchService(cmd);
if (srv == null)
return;
+ sock.setSoTimeout(0);
srv.execute(this, cmd);
}
}
--
1.6.3.2.416.g04d0
next prev parent reply other threads:[~2009-06-19 21:28 UTC|newest]
Thread overview: 11+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-06-19 21:27 [JGIT PATCH 0/6] Add timeouts to network IO Shawn O. Pearce
2009-06-19 21:27 ` [JGIT PATCH 1/6] Create input and output streams that have timeouts Shawn O. Pearce
2009-06-19 21:27 ` [JGIT PATCH 2/6] Add remote.name.timeout to configure an IO timeout Shawn O. Pearce
2009-06-19 21:27 ` [JGIT PATCH 3/6] Add timeouts to smart transport protocol clients Shawn O. Pearce
2009-06-19 21:27 ` [JGIT PATCH 4/6] Add timeouts to smart transport protocol servers Shawn O. Pearce
2009-06-19 21:27 ` Shawn O. Pearce [this message]
2009-06-19 21:27 ` [JGIT PATCH 6/6] Add --timeout command line options Shawn O. Pearce
2009-06-20 22:28 ` [JGIT PATCH 2/6] Add remote.name.timeout to configure an IO timeout Robin Rosenberg
2009-06-20 22:54 ` Shawn O. Pearce
2009-06-22 21:09 ` [JGIT PATCH 1/6] Create input and output streams that have timeouts Robin Rosenberg
2009-06-23 16:41 ` [JGIT PATCH 1/6 v2] " Shawn O. Pearce
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=1245446875-31102-6-git-send-email-spearce@spearce.org \
--to=spearce@spearce.org \
--cc=git@vger.kernel.org \
--cc=robin.rosenberg@dewire.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).