Skip to content
This repository has been archived by the owner on Jul 6, 2023. It is now read-only.

Orient Spring Data is not calling close() on the database connection. #71

Open
dalegarv opened this issue May 8, 2017 · 7 comments
Open
Assignees
Labels

Comments

@dalegarv
Copy link

dalegarv commented May 8, 2017

OrientDB Version: 2.2.18 Enterprise

Orient Spring Data Version: 0.14rc1

Java Version: 1.8

OS: SLES

Expected behavior

For every call to OrientObjectDatabaseFactory.openDatabase() there will be a matching call to DatabaseDocumentTxPooled.close() method so that the acquireCount will go back to 0.

Actual behavior

The openDatabase() method is getting called but not close().

Steps to reproduce

Create a simple test case that calls a find() method using Orient Spring Data, and follow it by a call to openDatabase(). Put a break points just before the call to find(), at the start of openDatabase(), and at the start of close(). The call to find() will cause a call to openDatabase() and the acquireCount will go to 1, but no call to be close() will be made. The second call to openDatabase() after the find() completes will show that the acquireCount is still 1 rather than being decremented back to 0.

Note that this behavior actually improves performance because the connection does not get destroyed since the acquireCount never goes to 0, so the next time the connection is used it's already connected.

@lvca lvca added the bug label May 8, 2017
@RAndrews137
Copy link
Contributor

Based on my prior knowledge of Orient Spring Data, I believe connection closing is tied to thread completion. When the thread using OSD has finished, it will trigger the connection to be closed. I don't believe Spring Data has syntax for closing a connection. I believe OSD is relying upon thread completion to convey when the connection is no longer needed and can be destroyed.

@RAndrews137
Copy link
Contributor

@robfrank A quick update on this ticket. I have been researching the matter with @dalegarv here at work. It had been over a year since I had reviewed the Orient Spring Data code in detail. I tried to find the code for connection closing after thread completion, but could not find it. I saw the shutdown hooks. In the research that @dalegarv performed, he believes the method below in OSD could be acquiring but not returning connections. The dbf.db() will acquire a connection, but there is no close() after the query is executed. Perhaps this should be in a try/catch/finally block.

Can you please review and confirm?

@OverRide
public <RET extends List> RET query(OQuery query, Object... args) {
return dbf.db().query(query, args);
}

@robfrank
Copy link
Contributor

thank you very much. I will verify tomorrow (I'm on UTC+1).
Once verified, maybe with a test based on your suggestions, i will release.

@robfrank
Copy link
Contributor

robfrank commented May 22, 2017

the lifecycle is managed by the transaction manager. Did you set up the TM? the hello sample app shows how to configure it.
The close should be called when all the result set is sent to the client, so it cannot be done in the repository.

@dalegarv
Copy link
Author

Yes, and I see an open/close pair being called by the transaction manager. But there's extra opens being called from the methods in org.springframework.data.orient.commons.core.AbstractOrientOperations that are never closed, so the OPartitionedDatabasePool acquiredCount never goes back to 0. For example:

@OverRide
public RET query(OQuery query, Object... args) {
return dbf.db().query(query, args);
}

@wongkimshing
Copy link

Any update on this issue, please? I encountered this problem as well and it will consumes all connections until the pool was empty. After that, it would be stuck and no response from DB coz no connections were released. It is kind of serious. Please support on this issue and it should be the time to release 0.15, right? Really appreciate.

@wongkimshing
Copy link

Could you please give a quick fix for this bug? Really appreciate

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

No branches or pull requests

5 participants