albertodonato / query-exporter

Export Prometheus metrics from SQL queries
GNU General Public License v3.0
436 stars 101 forks source link

Connection should close if there was an error executing the query #162

Open leoskyrocker opened 10 months ago

leoskyrocker commented 10 months ago

Describe the bug Currently, we're only closing the connection after executing a query if the keep_connected flag is set to false. However, if there is a connection error while executing the query, the query-exporter won't be able to re-use a connection subsequently, and hence it will continue to error out if keep_connected is configured to true.

Closing the connection is expected after after the query execution if there has been an exception.

A simple fix is to close the connection in the exception block (any exceptions). A more proper fix is to close the connection if the exception is related to a connection error.