Skip to content

Commit

Permalink
Fix connection cleanup on TFSTeamProjectCollection
Browse files Browse the repository at this point in the history
  • Loading branch information
albanf committed Feb 4, 2014
1 parent 3d45ad2 commit 17e3272
Showing 1 changed file with 19 additions and 1 deletion.
20 changes: 19 additions & 1 deletion src/main/java/hudson/plugins/tfs/model/Server.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
package hudson.plugins.tfs.model;

import com.microsoft.tfs.core.TFSConfigurationServer;
import hudson.plugins.tfs.TfTool;
import hudson.plugins.tfs.commands.ServerConfigurationProvider;
import hudson.plugins.tfs.util.MaskedArgumentListBuilder;

import java.io.File;
import java.io.IOException;
import java.io.Reader;
import java.lang.reflect.Field;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
Expand Down Expand Up @@ -136,7 +138,23 @@ public String getLocalHostname() throws IOException, InterruptedException {

public synchronized void close() {
if (this.tpc != null) {
this.tpc.close();
// Close the configuration server connection that should be closed by
// TFSTeamProjectCollection
// The field is private, so use reflection
// This should be removed when the TFS SDK is fixed
// Post in MSDN forum: social.msdn.microsoft.com/Forums/vstudio/en-US/79985ef1-b35d-4fc5-af0b-b95e28402b83
try {
Field f = TFSTeamProjectCollection.class.getDeclaredField("configurationServer");
f.setAccessible(true);
TFSConfigurationServer configurationServer = (TFSConfigurationServer) f.get(this.tpc);
if (configurationServer != null) {
configurationServer.close();
}
f.setAccessible(false);
} catch (NoSuchFieldException ignore) {
} catch (IllegalAccessException ignore) {
}
this.tpc.close();
}

}
Expand Down

0 comments on commit 17e3272

Please sign in to comment.