geoserver/geoserver — pull request #593 by jonescc (2014-05-23 07:14:11+00:00)
Title: Fix leaking jdbc connection when 'Return bounding box' is selected for WFS se...

...rvice

This issue occurred for us when requesting specific properties using the csv output format in Geoserver 2.4.2 against a postgis jdbc store but the problem also occurs in the latest nightly build for other output formats. For example, the following request in a test instance:

http://localhost:8080/geoserver/tiger/ows?service=WFS&version=1.0.0&request=GetFeature&typeName=tiger:profiles&propertyName=platform_number&maxFeatures=50&outputFormat=GML2

resulted in the following message in the log (when freeing memory)

[geotools.jdbc] - There is code leaving feature readers/iterators open, this is leaking statements and connections!

We eventually turned off 'return bounding box' to resolve this problem as we did not need this, but not before I'd worked out enough about what was happening to prepare this fix. I thought it may be useful for someone else.

The reason why the underlying jdbc Feature reader was not being closed was because in this instance it was being wrapped up by a FeatureBoundsFeatureCollection which did not implement Closeable. When using fc.getFeatures in the CSVOutputFormat the iterator returned uses DataUtilities.close to close the wrapped Iterator which checks for Closeable being implemented before closing the wrapped iterator (yes featureBoundsFeatureCollection is wrapped by another iterator).

Not sure if this is an appropriate fix or test, but you get the idea.