logstash-plugins / logstash-integration-jdbc

Logstash Integration Plugin for JDBC, including Logstash Input and Filter Plugins
Apache License 2.0
53 stars 54 forks source link

Logstash does not reconnect when Sybase raises "Connection is already closed" #163

Open kaisecheng opened 6 months ago

kaisecheng commented 6 months ago

Similar issue to https://github.com/logstash-plugins/logstash-integration-jdbc/issues/143 , https://github.com/logstash-plugins/logstash-integration-jdbc/issues/152 , this time is Sybase. ~The upstream Sequel driver is affected by a connection issue as described in https://github.com/jeremyevans/sequel/issues/2159~ Sequel lib doesn't support Sybase, hence, the plugin needs special handling for Sybase to solve this issue.

def DB.disconnect_error?(exception, opts)
  super || exception.message =~ /Connection is already closed\.\z/
end

This problem is caused when a connection gets closed by Sybase (idle sessions, workload rules, network issues, etc.) Logstash should gracefully recover from those errors, discarding the stale connection and reconnecting the client. Instead, the plugin hangs trying to reuse the closed/invalid connections.

kaisecheng commented 6 months ago

A workaround is enabling jdbc_validate_connection and set the jdbc_validation_timeout to a smaller interval value compared to the schedule option

for example a scheduler runs for every minute, jdbc_validation_timeout should be smaller than 60 seconds.

schedule => "* * * * *"
jdbc_validate_connection => true
jdbc_validation_timeout => 55 # 55 seconds