提交 607f8506 编写于 作者: K kohsuke

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
上级 fe8df965
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);
}
}
......@@ -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.
* <p>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册