From bc3252dbf0dca36b316c6c97bc84d473b6f27e25 Mon Sep 17 00:00:00 2001 From: Michael Bayne Date: Tue, 15 Aug 2017 09:32:13 -0700 Subject: [PATCH] Default to a 30s read timeout during downloads. This is configurable via a system property -Dread_timeout=N. --- src/main/java/com/threerings/getdown/data/SysProps.java | 8 ++++++++ .../java/com/threerings/getdown/net/HTTPDownloader.java | 5 +++++ 2 files changed, 13 insertions(+) diff --git a/src/main/java/com/threerings/getdown/data/SysProps.java b/src/main/java/com/threerings/getdown/data/SysProps.java index de620c9..ceb1fab 100644 --- a/src/main/java/com/threerings/getdown/data/SysProps.java +++ b/src/main/java/com/threerings/getdown/data/SysProps.java @@ -95,6 +95,14 @@ public class SysProps return Integer.getInteger("connect_timeout", 0); } + /** Specifies the read timeout (in seconds) to use when downloading all files from the server. + * The default is 30 seconds, meaning that if a download stalls for more than 30 seconds, the + * update process wil fail. Setting the timeout to zero (or a negative value) will disable it. + * Usage: {@code -Dread_timeout=N}. */ + public static int readTimeout () { + return Integer.getInteger("read_timeout", 30); + } + /** Parses a Java version system property using the supplied regular expression. The numbers * extracted from the regexp will be placed in each consecutive hundreds position in the * returned value. diff --git a/src/main/java/com/threerings/getdown/net/HTTPDownloader.java b/src/main/java/com/threerings/getdown/net/HTTPDownloader.java index 286ebc5..139e116 100644 --- a/src/main/java/com/threerings/getdown/net/HTTPDownloader.java +++ b/src/main/java/com/threerings/getdown/net/HTTPDownloader.java @@ -15,6 +15,7 @@ import java.util.List; import com.samskivert.io.StreamUtil; import com.threerings.getdown.data.Resource; +import com.threerings.getdown.data.SysProps; import com.threerings.getdown.util.ConnectionUtil; import static com.threerings.getdown.Log.log; @@ -60,6 +61,10 @@ public class HTTPDownloader extends Downloader { // download the resource from the specified URL URLConnection conn = ConnectionUtil.open(rsrc.getRemote()); + int rtimeout = SysProps.readTimeout(); + if (rtimeout > 0) { + conn.setReadTimeout(rtimeout * 1000); + } conn.connect(); // make sure we got a satisfactory response code