baruwaproject / baruwa2

Baruwa 2.0
http://www.baruwa.org
GNU General Public License v3.0
21 stars 9 forks source link

[Enhancement] Perform retries on connection failure for BSQL process #118

Closed rmoesbergen closed 7 years ago

rmoesbergen commented 7 years ago

The BaruwaSQL process starts up every few hours. However, when the connection to de backend database fails, there is no retry, and the process does not start. This means that until the next restart cycle, logging will go to backup, instead of the database. Please add a retry mechanism to the database connection sequence to make this more robust.

rmoesbergen commented 7 years ago

Maybe it helps to increase the time-out of the connection to a little more than 10 seconds? If the database (or sphinx cache) is busy, it might take a little longer. Would that also explain why I don't see anything in the logs, because the timeout is a 'die()' call?

`` sub connect2db { $db_user = MailScanner::Config::Value('dbusername') if ( !defined($db_user) ); $db_pass = MailScanner::Config::Value('dbpassword') if ( !defined($db_pass) ); $baruwa_dsn = MailScanner::Config::Value('dbdsn') if ( !defined($baruwa_dsn) ); eval { local $SIG{ALRM} = sub { die "TIMEOUT\n" }; eval { alarm(10); $conn = DBI->connect_cached( $baruwa_dsn, $db_user, $db_pass, { PrintError => 0, AutoCommit => 1, private_foo_cachekey => 'baruwa', RaiseError => 1, ShowErrorStatement => 1, pg_enable_utf8 => 1 } ) unless $conn && $conn->ping;

akissa commented 7 years ago

Added an external watcher process to address the BSQL process not being available.