From 4e3b5670a055ac37bc08f9e71a5e0a5f2fb590fd Mon Sep 17 00:00:00 2001 From: md_5 Date: Thu, 25 Sep 2014 10:52:16 +1000 Subject: [PATCH] [#1224] Add connect / read timeout for module download incase Jenkins is down. --- .../java/net/md_5/bungee/module/JenkinsModuleSource.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/proxy/src/main/java/net/md_5/bungee/module/JenkinsModuleSource.java b/proxy/src/main/java/net/md_5/bungee/module/JenkinsModuleSource.java index cbc36e68..42453eaa 100644 --- a/proxy/src/main/java/net/md_5/bungee/module/JenkinsModuleSource.java +++ b/proxy/src/main/java/net/md_5/bungee/module/JenkinsModuleSource.java @@ -4,6 +4,7 @@ import com.google.common.io.ByteStreams; import com.google.common.io.Files; import java.io.IOException; import java.net.URL; +import java.net.URLConnection; import lombok.Data; import net.md_5.bungee.Util; @@ -18,7 +19,12 @@ public class JenkinsModuleSource implements ModuleSource try { URL website = new URL( "http://ci.md-5.net/job/BungeeCord/" + version.getBuild() + "/artifact/module/" + module.getName().replace( '_', '-' ) + "/target/" + module.getName() + ".jar" ); - Files.copy( ByteStreams.newInputStreamSupplier( ByteStreams.toByteArray( website.openStream() ) ), module.getFile() ); + URLConnection con = website.openConnection(); + // 15 second timeout at various stages + con.setConnectTimeout( 15000 ); + con.setReadTimeout( 15000 ); + + Files.copy( ByteStreams.newInputStreamSupplier( ByteStreams.toByteArray( con.getInputStream() ) ), module.getFile() ); System.out.println( "Download complete" ); } catch ( IOException ex ) {