diff options
author | Christian Grothoff <christian@grothoff.org> | 2017-07-04 23:33:57 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2017-07-04 23:33:57 +0200 |
commit | 5d6dfde04413dd08d3056a724ace0cb6c99d4117 (patch) | |
tree | dbf81e82d03fef0bbe7d3f8dc7718f7b72b68467 /src/auditordb | |
parent | f9950799fc21c6847d13f93aaec2cd6a555d546a (diff) | |
download | exchange-5d6dfde04413dd08d3056a724ace0cb6c99d4117.tar.gz exchange-5d6dfde04413dd08d3056a724ace0cb6c99d4117.tar.bz2 exchange-5d6dfde04413dd08d3056a724ace0cb6c99d4117.zip |
fix #4955 in auditordb, clean up fix in exchangedb
Diffstat (limited to 'src/auditordb')
-rw-r--r-- | src/auditordb/plugin_auditordb_postgres.c | 23 |
1 files changed, 21 insertions, 2 deletions
diff --git a/src/auditordb/plugin_auditordb_postgres.c b/src/auditordb/plugin_auditordb_postgres.c index 38894c8c..4862cf20 100644 --- a/src/auditordb/plugin_auditordb_postgres.c +++ b/src/auditordb/plugin_auditordb_postgres.c @@ -821,8 +821,11 @@ static void db_conn_destroy (void *cls) { struct TALER_AUDITORDB_Session *session = cls; - PGconn *db_conn = session->conn; + PGconn *db_conn; + if (NULL == session) + return; + db_conn = session->conn; if (NULL != db_conn) PQfinish (db_conn); GNUNET_free (session); @@ -844,7 +847,23 @@ postgres_get_session (void *cls) struct TALER_AUDITORDB_Session *session; if (NULL != (session = pthread_getspecific (pc->db_conn_threadlocal))) - return session; + { + if (CONNECTION_BAD == PQstatus (session->conn)) + { + /** + * Reset the thread-local database-handle. Disconnects from the + * DB. Needed after the database server restarts as we need to + * properly reconnect. */ + GNUNET_assert (0 == pthread_setspecific (pc->db_conn_threadlocal, + NULL)); + PQfinish (session->conn); + GNUNET_free (session); + } + else + { + return session; + } + } db_conn = connect_to_postgres (pc); if (NULL == db_conn) return NULL; |