-
Notifications
You must be signed in to change notification settings - Fork 74
Closed
Description
This has not been a major issue because the recommendation is that applications share one DatabaseClient instance throughout the life of the application and and call release when the application is ready to terminate. However, we want to be a good citizen and close all the resources we open. This bug demonstrates we are not doing this in this case.
import com.marklogic.client.DatabaseClient;
import com.marklogic.client.DatabaseClientFactory;
import com.marklogic.client.DatabaseClientFactory.DigestAuthContext;
import com.marklogic.client.io.FileHandle;
import com.marklogic.client.semantics.GraphManager;
import com.marklogic.client.semantics.RDFMimeTypes;
import java.io.*;
// minimal java api client test which illustrates CLOSE_WAIT
public class CloseWaitTest {
public static DatabaseClient writerClient = DatabaseClientFactory.newClient("localhost", 8000,
new DigestAuthContext("admin", "admin"));
protected static final String TESTFILE = "rdfxml.rdf";
public static void main(String[] args) throws Exception {
try {
File testData = new File(TESTFILE);
FileHandle testHandle = new FileHandle(testData);
GraphManager gmgr = writerClient.newGraphManager();
gmgr.setDefaultMimetype(RDFMimeTypes.RDFXML);
gmgr.merge("/directory1/test.rdf", testHandle);
gmgr.delete("/directory1/test.rdf");
} catch (Exception ex) {
throw ex;
} finally {
writerClient.release();
writerClient = null;
// increase Thread.sleep or set breakpoints on gmgr.merge and gmgr.delete to observe CLOSE_WAIT
Thread.sleep(100000);
}
}
}
Then on linux, while the Thread.sleep is still going, run the following to see the connections still in close wait:
netstat -an | grep 8000 | grep CLOSE_WAIT