path: root/util
diff options
author/C=EU/ST=EU/CN=Pablo Neira Ayuso/ </C=EU/ST=EU/CN=Pablo Neira Ayuso/>2008-04-05 14:02:56 +0000
committer/C=EU/ST=EU/CN=Pablo Neira Ayuso/ </C=EU/ST=EU/CN=Pablo Neira Ayuso/>2008-04-05 14:02:56 +0000
commit19e26b39ba4b571b36883cb4fc08a16d4b7b1c38 (patch)
tree8b60b0e6570d10af67e0eda53d361a46d5f40a2e /util
parent627afbf16b96d23dc0eb7b8e87575c3b9b54e72b (diff)
This patch fixes a problem in SQL reconnection algorithm which is managed in
the db.c file for PgSQL and MySQL. In case of problem during request execution a new connection to the database was immediatly started without closing the previous one. The consequence was to block the database by having too much simultaneous open connections. This patch fixes the problem by disconnectinng from the database after a request failure and trying to reconnect after a delay which is by default of 2 secondes. This delay can be customized via the reconnect configuration variable in the database configuration section. Signed-off-by: Eric Leblond <>
Diffstat (limited to 'util')
1 files changed, 7 insertions, 2 deletions
diff --git a/util/db.c b/util/db.c
index 49f6c29..b9ca8db 100644
--- a/util/db.c
+++ b/util/db.c
@@ -176,6 +176,8 @@ static int _init_reconnect(struct ulogd_pluginstance *upi)
struct db_instance *di = (struct db_instance *) upi->private;
if (reconnect_ce(upi->config_kset).u.value) {
+ if (time(NULL) < di->reconnect)
+ return -1;
di->reconnect = time(NULL);
if (di->reconnect != TIME_ERR) {
ulogd_log(ULOGD_ERROR, "no connection to database, "
@@ -312,8 +314,11 @@ static int __interp_db(struct ulogd_pluginstance *upi)
/* now we have created our statement, insert it */
- if (di->driver->execute(upi, di->stmt, strlen(di->stmt)) < 0)
- return _init_db(upi);
+ if (di->driver->execute(upi, di->stmt, strlen(di->stmt)) < 0) {
+ /* error occur, database connexion need to be closed */
+ di->driver->close_db(upi);
+ return _init_reconnect(upi);
+ }
return 0;