Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Can a JIRA add-on cause a DB connection leak?

Marc-Andre Thibodeau June 29, 2015

Might be a dummy question, but I'm risking it anyway... smile  Is it possible for an add-on to cause a DB connection leak in JIRA? Assuming the add-on uses nothing else than the ActiveObjects class to query the database and that the add-on never gets a hold on the Connection object, my assumption is that the answer is no.  But I might me missing something...  Could there be ways of using ActiveObjects that would cause it not to free DB connections?

2 answers

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

3 votes
Answer accepted
crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 29, 2015

Since add-ons have access to essentially anything in the JVM, it is absolutely possible for an add-on to cause a connection leak, and this has happened many times in the past.

First, the obvious problems... JIRA's OfBizDelegator is available in the API and the raw entity-engine transaction-related classes are de facto API by virtue of transitive dependencies.  It is quite easy to leak a connection by doing something naughty through them.  Examples include:

  • Using findListIteratorByCondition or any of the other methods that return OfBizListIterator and failing to close() it;
  • Beginning a "local" transaction with TransactionUtil and failing to ever commit it or roll it back.  In a request thread this would be caught by RequestCleanupStep, but that protective safeguard is lost if the add-on creates its own thread pool.  The reason starting a transaction and failing to close it leaks a connection has to do with the way that entity-engine manages connections.  Normally, connections are immediately returned to the thread pool, but if you start a transaction then it is held in a ThreadLocal until you commit it.

Further, nothing actually forces an add-on to stick with the API.  It can go directly to the jira-core class OfBizConnectionFactory, call getConnection() on it, and go to town.

Finally, even in the Active Objects world, it is possible to get a raw Connection by using EntityManager.getProvider().getConnection(). Several of the more advanced add-ons do this to get more control over their queries on the Active Objects tables when they run into AO's limitations.

In short, yes.

0 votes
Marc-Andre Thibodeau June 29, 2015

Thanks Chris, very clear.

So basically, if an add-on sticks with using the standard AO query API and uses declarative transactions, it should stay out of trouble, DB-connection wise...

Cheers,

Marc

crf
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 29, 2015

To the best of my knowledge, yes.

TAGS
AUG Leaders

Atlassian Community Events