arangodb / arangodb-java-driver

The official ArangoDB Java driver.

Repository from Github https://github.comarangodb/arangodb-java-driverRepository from Github https://github.comarangodb/arangodb-java-driver

Exception thrown from "executor.disconnect()" leads to CommunicationProtocol remaining open

wajda opened this issue · comments

@Override
    public void shutdown() throws ArangoDBException {
        try {
            executor.disconnect();
            cp.close(); // <---- This is not called when the previous method throws an exception !!!
        } catch (final IOException e) {
            throw new ArangoDBException(e);
        }
    }

When an exception is thrown from the executor.disconnect() (for instance 401 - unauthorized) the CommunicationProtocol.close() isn't called and thus all the associated with it resources (apparently including thread pools or such) remain unclosed. This leads to the client app being unable to exit normally.

AN easy workaround is to call shutdown() in a try-catch block and repeat the call on ArangoDBException like this:

    try {
      arango.shutdown()
    } catch {
      case _: ArangoDBException =>
        arango.shutdown()
    }

It would be good however, to handle exceptions internally in the driver and do a proper cleanup.

Hi @wajda , thanks for spotting this. I created #400 which improves the safety of the shutdown task. Does it solve your case?

Yes, now it works as expected. Thank you very much!