Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
[jgit-dev] Closing jgit Daemon not releasing port

Hi,

 

I am trying to use jgit 4.5.2 in a java 7 project and I am facing the following problem. I hope that you can help me figure out if I am doing something wrong, or if there is an actual problem with the library.

 

I have the jgit daemon started before each of my project’s test cases, and after each test case finishes its execution, it is being stopped.

The initialization is done with the following way:

 

                server = new GitDaemon(new InetSocketAddress(9418));

                boolean uploadsEnabled = true;

                server.getService("git-receive-pack").setEnabled(uploadsEnabled);

                server.setRepositoryResolver(new RepositoryResolverImplementation());

                server.start();

 

and the closure using:

                if (server != null && server.isRunning()) {

                                server.stop();

                                server = null;

                }

 

What I notice though is that the close() method in Daemon.java fails to actually stop the daemon and release the port, so the following test case will complain that the port is already in use.

 

Failed to initialized git daemon: Address already in use: JVM_Bind

java.net.BindException: Address already in use: JVM_Bind

 

After looking into it, it feels like there is a problem in the Daemon class, for the following reason:

 

Method Daemon#close() triggers an  interrupt on the acceptThread and that assumes that the thread will receive the InterruptedIOException and will exit the infinite loop, thus reaching the point that closes the socket. That is not the case though as, inside the thread, listenSock.accept() is being called that is a blocking method that is not responsive to thread interruption. Since it ignores the interruption, the thread doesn’t move to the next step of releasing the resources until an actual new requests arrives. Until then, the thread will remain stuck waiting.

 

Can you please confirm if this is indeed the case?

 

Thank you in advance,

Georgios

 

 

 

 


Back to the top