Fix PostgreSQL resync error detection

Add flush() call in resync_start() for immediate socket error detection instead of deferring to event loop
v3.0_pgsql-resync-error-detection
Rahim Kanji 1 month ago
parent 176362c77d
commit 1ffb4f13ac

@ -364,7 +364,7 @@ public:
bool is_connected() const;
void compute_unknown_transaction_status();
void async_free_result();
void flush();
void flush(bool is_resync = false);
bool IsActiveTransaction();
bool IsKnownActiveTransaction();
bool IsServerOffline();

@ -1212,7 +1212,7 @@ void PgSQL_Connection::fetch_result_cont(short event) {
}
}
void PgSQL_Connection::flush() {
void PgSQL_Connection::flush(bool is_resync) {
int res = PQflush(pgsql_conn);
if (res > 0) {
@ -1222,7 +1222,11 @@ void PgSQL_Connection::flush() {
async_exit_status = PG_EVENT_READ;
}
else {
set_error_from_PQerrorMessage();
if (!is_resync) {
set_error_from_PQerrorMessage();
} else {
resync_failed = true;
}
proxy_error("Failed to flush data to backend. %s\n", get_error_code_with_message().c_str());
async_exit_status = PG_EVENT_NONE;
}
@ -1773,7 +1777,7 @@ void PgSQL_Connection::resync_start() {
resync_failed = true;
return;
}
async_exit_status = PG_EVENT_WRITE;
flush(true);
}
void PgSQL_Connection::resync_cont(short event) {
@ -1781,17 +1785,7 @@ void PgSQL_Connection::resync_cont(short event) {
proxy_debug(PROXY_DEBUG_MYSQL_PROTOCOL, 6, "event=%d\n", event);
async_exit_status = PG_EVENT_NONE;
if (event & POLLOUT) {
int res = PQflush(pgsql_conn);
if (res > 0) {
async_exit_status = PG_EVENT_WRITE;
} else if (res == 0) {
async_exit_status = PG_EVENT_READ;
} else {
proxy_error("Failed to flush data to backend.\n");
async_exit_status = PG_EVENT_NONE;
resync_failed = true;
}
flush(true);
}
}

Loading…
Cancel
Save