aboutsummaryrefslogtreecommitdiff
path: root/src/pq/pq_event.c
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2021-11-25 14:03:04 +0100
committerChristian Grothoff <christian@grothoff.org>2021-11-25 14:03:04 +0100
commitb9644ee3066924eefa8ea2b75fbd20538ad7ce03 (patch)
tree357ffcb57159b9f5a19bf3ea01a3778624346ba7 /src/pq/pq_event.c
parentc5a7ce5d22f57e3a248ae3e9bc4541a35495b8a1 (diff)
downloadgnunet-b9644ee3066924eefa8ea2b75fbd20538ad7ce03.tar.gz
gnunet-b9644ee3066924eefa8ea2b75fbd20538ad7ce03.zip
fix event loop subscriptions on DB reconnect
Diffstat (limited to 'src/pq/pq_event.c')
-rw-r--r--src/pq/pq_event.c20
1 files changed, 19 insertions, 1 deletions
diff --git a/src/pq/pq_event.c b/src/pq/pq_event.c
index 283e4569c..98a28c317 100644
--- a/src/pq/pq_event.c
+++ b/src/pq/pq_event.c
@@ -194,9 +194,15 @@ event_do_poll (struct GNUNET_PQ_Context *db)
194 "PG poll job active\n"); 194 "PG poll job active\n");
195 if (1 != 195 if (1 !=
196 PQconsumeInput (db->conn)) 196 PQconsumeInput (db->conn))
197 {
197 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, 198 GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
198 "Failed to read from Postgres: %s\n", 199 "Failed to read from Postgres: %s\n",
199 PQerrorMessage (db->conn)); 200 PQerrorMessage (db->conn));
201 if (CONNECTION_BAD != PQstatus (db->conn))
202 return;
203 GNUNET_PQ_reconnect (db);
204 return;
205 }
200 while (NULL != (n = PQnotifies (db->conn))) 206 while (NULL != (n = PQnotifies (db->conn)))
201 { 207 {
202 struct GNUNET_ShortHashCode sh; 208 struct GNUNET_ShortHashCode sh;
@@ -263,10 +269,20 @@ do_scheduler_notify (void *cls)
263 struct GNUNET_PQ_Context *db = cls; 269 struct GNUNET_PQ_Context *db = cls;
264 270
265 db->event_task = NULL; 271 db->event_task = NULL;
266 GNUNET_assert (NULL != db->rfd); 272 if (NULL == db->rfd)
273 GNUNET_PQ_reconnect (db);
267 event_do_poll (db); 274 event_do_poll (db);
275 if (NULL != db->event_task)
276 return;
268 GNUNET_log (GNUNET_ERROR_TYPE_INFO, 277 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
269 "Resubscribing\n"); 278 "Resubscribing\n");
279 if (NULL == db->rfd)
280 {
281 db->event_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS,
282 &do_scheduler_notify,
283 db);
284 return;
285 }
270 db->event_task 286 db->event_task
271 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL, 287 = GNUNET_SCHEDULER_add_read_net (GNUNET_TIME_UNIT_FOREVER_REL,
272 db->rfd, 288 db->rfd,
@@ -329,6 +345,8 @@ manage_subscribe (struct GNUNET_PQ_Context *db,
329 char *end; 345 char *end;
330 PGresult *result; 346 PGresult *result;
331 347
348 if (NULL == db->conn)
349 return;
332 end = stpcpy (sql, 350 end = stpcpy (sql,
333 cmd); 351 cmd);
334 end = sh_to_channel (&eh->sh, 352 end = sh_to_channel (&eh->sh,