JdbcCollector does not close database connections correctly

Description

When using the JdbcCollector for a MySQL 5.7 server, I saw the following notes in mysql.log:

2016-04-14T13:05:44.692827Z 77 [Note] Aborted connection 77 to db:'information_schema' user: 'opennms' host: '10.1.15.17' (Got an error reading communication packets) 2016-04-14T13:05:44.692829Z 73 [Note] Aborted connection 73 to db:'information_schema' user: 'opennms' host: '10.1.15.17' (Got an error reading communication packets) 2016-04-14T13:05:44.692966Z 89 [Note] Aborted connection 89 to db:'information_schema' user: 'opennms' host: '10.1.15.17' (Got an error reading communication packets) 2016-04-14T13:05:44.693006Z 95 [Note] Aborted connection 95 to db:'information_schema' user: 'opennms' host: '10.1.15.17' (Got an error reading communication packets)

These lines occur on every datacollection interval and stil occur if Polling and Provisioning were disabled. When I disable Collectd I can't see these lines anymore. So there seems to be an issue with the connection handling in JdbcCollector.

I did some further investigation with wireshark. Per collected value a new JDBC connection was created, but only for a few connections I saw a MySQL close at the end before TCP FIN.

Acceptance / Success Criteria

None

Attachments

2
  • 08 Jun 2016, 07:05 AM
  • 08 Jun 2016, 07:05 AM

Lucidchart Diagrams

Activity

Show:

Seth Leger June 29, 2016 at 2:51 PM

Merged into foundation branch. Marking as fixed.

commit d5443cb599ad8dde804a967c5634d96d62c36ae5

Seth Leger June 28, 2016 at 10:48 PM

This should be merged into our stable branches since it could cause resource leaks in any scenario where the JDBC collector is being used heavily.

Michael Batz June 8, 2016 at 7:05 AM

I had a look into the source and the problem seems to be in features/jdbc-collector/src/main/java/org/opennms/netmgt/collectd/JdbcCollector.java or in features/jdbc-collector/src/main/java/org/opennms/netmgt/collectd/jdbc/JdbcAgentState.java

In method collect(...) ofJdbcCollector, there is a loop for each query of the collection. For every run of the loop, a new connection will be created with

con = agentState.getJdbcConnection();

But this connection will not be closed at the end of the loop. A connection close is done after the loop. So only the last database connection will be closed. I created a patch (see attached files) which solves the issue in my environment in OpenNMS 17.1.1.

Fixed

Details

Assignee

Reporter

Labels

Affects versions

Priority

PagerDuty

Created June 8, 2016 at 5:53 AM
Updated June 29, 2016 at 6:38 PM
Resolved June 29, 2016 at 2:51 PM

Flag notifications