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.
This commit is contained in:
Joris Vink 2019-09-04 19:19:52 +02:00
parent b54b93536d
commit f3b7cba58c
1 changed files with 15 additions and 2 deletions

View File

@ -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) {