Skip to content

Commit 744fe5d

Browse files
Philipp Takacsomar-polo
authored andcommitted
limit retries
1 parent 2e1fde8 commit 744fe5d

File tree

1 file changed

+12
-2
lines changed

1 file changed

+12
-2
lines changed

table_postgres.c

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -311,9 +311,14 @@ table_postgres_query(const char *key, int service)
311311
PGresult *res;
312312
const char *errfld;
313313
char *stmt;
314-
int i;
314+
int i, retry_times = 2;
315315

316316
retry:
317+
retry_times--;
318+
if (retry_times < 0) {
319+
log_warnx("warn: table-postgres: to many retries");
320+
return NULL;
321+
}
317322
stmt = NULL;
318323
for (i = 0; i < SQL_MAX; i++) {
319324
if (service == 1 << i) {
@@ -444,12 +449,17 @@ table_postgres_fetch(int service, struct dict *params, char *dst, size_t sz)
444449
char *stmt;
445450
PGresult *res;
446451
const char *k, *errfld;
447-
int i;
452+
int i, retry_times = 1;
448453

449454
if (config->db == NULL && config_connect(config) == 0)
450455
return -1;
451456

452457
retry:
458+
retry_times--;
459+
if (retry_times < 0) {
460+
log_warnx("warn: table-postgres: to many retries");
461+
return -1;
462+
}
453463
if (service != K_SOURCE)
454464
return -1;
455465

0 commit comments

Comments
 (0)