From 607f8506c4ae9a4182d40c7a048d1ac3d96a4e85 Mon Sep 17 00:00:00 2001 From: kohsuke Date: Wed, 18 Feb 2009 23:53:57 +0000 Subject: [PATCH] Always use some timeout value for Subversion HTTP access to avoid infinite hang in the read. git-svn-id: https://hudson.dev.java.net/svn/hudson/trunk/hudson/main@15443 71c3de6d-444a-0410-be80-ed276b4c234a --- .../scm/FilterSVNAuthenticationManager.java | 64 +++++++++++++++++++ .../main/java/hudson/scm/SubversionSCM.java | 18 ++++++ 2 files changed, 82 insertions(+) create mode 100644 core/src/main/java/hudson/scm/FilterSVNAuthenticationManager.java diff --git a/core/src/main/java/hudson/scm/FilterSVNAuthenticationManager.java b/core/src/main/java/hudson/scm/FilterSVNAuthenticationManager.java new file mode 100644 index 0000000000..8b7d7a5112 --- /dev/null +++ b/core/src/main/java/hudson/scm/FilterSVNAuthenticationManager.java @@ -0,0 +1,64 @@ +package hudson.scm; + +import org.tmatesoft.svn.core.auth.ISVNAuthenticationManager; +import org.tmatesoft.svn.core.auth.ISVNAuthenticationProvider; +import org.tmatesoft.svn.core.auth.ISVNProxyManager; +import org.tmatesoft.svn.core.auth.SVNAuthentication; +import org.tmatesoft.svn.core.SVNURL; +import org.tmatesoft.svn.core.SVNException; +import org.tmatesoft.svn.core.SVNErrorMessage; +import org.tmatesoft.svn.core.io.SVNRepository; + +import javax.net.ssl.TrustManager; + +/** + * {@link ISVNAuthenticationManager} filter. Useful for customizing the behavior by delegation. + * @author Kohsuke Kawaguchi + */ +public class FilterSVNAuthenticationManager implements ISVNAuthenticationManager { + protected ISVNAuthenticationManager core; + + public FilterSVNAuthenticationManager(ISVNAuthenticationManager core) { + this.core = core; + } + + public void setAuthenticationProvider(ISVNAuthenticationProvider provider) { + core.setAuthenticationProvider(provider); + } + + public ISVNProxyManager getProxyManager(SVNURL url) throws SVNException { + return core.getProxyManager(url); + } + + public TrustManager getTrustManager(SVNURL url) throws SVNException { + return core.getTrustManager(url); + } + + public SVNAuthentication getFirstAuthentication(String kind, String realm, SVNURL url) throws SVNException { + return core.getFirstAuthentication(kind, realm, url); + } + + public SVNAuthentication getNextAuthentication(String kind, String realm, SVNURL url) throws SVNException { + return core.getNextAuthentication(kind, realm, url); + } + + public void acknowledgeAuthentication(boolean accepted, String kind, String realm, SVNErrorMessage errorMessage, SVNAuthentication authentication) throws SVNException { + core.acknowledgeAuthentication(accepted, kind, realm, errorMessage, authentication); + } + + public void acknowledgeTrustManager(TrustManager manager) { + core.acknowledgeTrustManager(manager); + } + + public boolean isAuthenticationForced() { + return core.isAuthenticationForced(); + } + + public int getReadTimeout(SVNRepository repository) { + return core.getReadTimeout(repository); + } + + public int getConnectTimeout(SVNRepository repository) { + return core.getConnectTimeout(repository); + } +} diff --git a/core/src/main/java/hudson/scm/SubversionSCM.java b/core/src/main/java/hudson/scm/SubversionSCM.java index 4ef9b071da..7e7661ca4b 100644 --- a/core/src/main/java/hudson/scm/SubversionSCM.java +++ b/core/src/main/java/hudson/scm/SubversionSCM.java @@ -1406,6 +1406,17 @@ public class SubversionSCM extends SCM implements Serializable { SVNRepository repository = SVNRepositoryFactory.create(repoURL); ISVNAuthenticationManager sam = SVNWCUtil.createDefaultAuthenticationManager(); + sam = new FilterSVNAuthenticationManager(sam) { + // If there's no time out, the blocking read operation may hang forever, because TCP itself + // has no timeout. So always use some time out. If the underlying implementation gives us some + // value (which may come from ~/.subversion), honor that, as long as it sets some timeout value. + @Override + public int getReadTimeout(SVNRepository repository) { + int r = super.getReadTimeout(repository); + if(r<=0) r = DEFAULT_TIMEOUT; + return r; + } + }; sam.setAuthenticationProvider(createAuthenticationProvider()); repository.setAuthenticationManager(sam); @@ -1612,6 +1623,13 @@ public class SubversionSCM extends SCM implements Serializable { private static final Logger LOGGER = Logger.getLogger(SubversionSCM.class.getName()); + /** + * Network timeout in milliseconds. + * The main point of this is to prevent infinite hang, so it should be a rather long value to avoid + * accidental time out problem. + */ + public static int DEFAULT_TIMEOUT = Integer.getInteger(SubversionSCM.class.getName()+".timeout",3600*1000); + /** * Enables trace logging of Ganymed SSH library. *

-- GitLab