From f3b7cba58cc8051997b9b072243c8553c6d23b6a Mon Sep 17 00:00:00 2001 From: Joris Vink Date: Wed, 4 Sep 2019 19:19:52 +0200 Subject: [PATCH] Call PQConsumeInput() again after PQisBusy(). Prevents a stall in case there is still data in the read end of the socket but PQisBusy() told us to not fetch a result yet. In that case we end up stalling due to epoll not giving us another EPOLLIN event due to EPOLLET. --- src/pgsql.c | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/pgsql.c b/src/pgsql.c index 234dfd0..910618f 100644 --- a/src/pgsql.c +++ b/src/pgsql.c @@ -632,6 +632,12 @@ pgsql_conn_create(struct kore_pgsql *pgsql, struct pgsql_db *db) return (NULL); } + if (PQsetnonblocking(conn->db, 1) == -1) { + pgsql_set_error(pgsql, PQerrorMessage(conn->db)); + pgsql_conn_cleanup(conn); + return (NULL); + } + return (conn); } @@ -715,8 +721,15 @@ pgsql_read_result(struct kore_pgsql *pgsql) PGnotify *notify; if (PQisBusy(pgsql->conn->db)) { - pgsql->state = KORE_PGSQL_STATE_WAIT; - return; + if (!PQconsumeInput(pgsql->conn->db)) { + pgsql->state = KORE_PGSQL_STATE_ERROR; + pgsql->error = kore_strdup( + PQerrorMessage(pgsql->conn->db)); + return; + } else if (PQisBusy(pgsql->conn->db)) { + pgsql->state = KORE_PGSQL_STATE_WAIT; + return; + } } while ((notify = PQnotifies(pgsql->conn->db)) != NULL) {