Skip to content

Connections are left in CLOSE_WAIT after DatabaseClient.release is called #467

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
sammefford opened this issue Aug 31, 2016 · 4 comments
Closed

Comments

@sammefford
Copy link
Contributor

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
@sammefford
Copy link
Contributor Author

Here's a description of TIME_WAIT connections with respect to Apache httpclient. The description of TIME_WAIT vs CLOSE_WAIT comes across strange to me, but for what it's worth:
http://wiki.apache.org/HttpComponents/FrequentlyAskedConnectionManagementQuestions

@georgeajit
Copy link

Updating this Git Issue, with comments taken from MarkLogic Bug Track system ( https://bugtrack.marklogic.com/41543)

QA Test Results / Oberservations on Windows Cluster running MarkLogic Server build - 8.0-5.8.
Able to reproduce the issue on a Java Client API branch checked on August 25 2016 with branch 3.0-develop. Used the test code from Sam and ran the test using gradle command.

Commands run are:

cd java-client-api-dev
git checkout 3.0-develop
git branch

mvn clean
mvn compile
mvn -Dmaven.test.skip=true -Dmaven.javadoc.skip=true install
cd test-complete
chmod +x gradlew

Changed one of the test to have Sam's code to reproduce the issue
Copied the required data file into a folder(into "c:" for Windows)

./gradlew clean
./gradlew complie
./gradlew -Dtest.single=TestSearchOnJSON test

On admin GUI verified that there are fragments after the delete of graph (doc) from the sample test code.
On a separate cygwin window, run netstat -an|grep 8011|grep CLOSE_WAIT

Was able to see connection in CLOSE_WAIT.

Did a checkout of latest 3.0-develop into another folder.
Repeated the above steps.
Did not see connection in CLOSE_WAIT.

Tested on Linux cluster with same procedures.
Did not see CLOSE_WAIT with the sample test code.

@georgeajit georgeajit added ship and removed test labels Sep 7, 2016
@georgeajit
Copy link

The issue is fixed. Ran the tests on release-3.0.5.1 branch of Java Client API on MarkLogic Server build 8.0-5.8 version.

@grechaw
Copy link
Contributor

grechaw commented Sep 7, 2016

Issue won't sync if its closed.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants