diff --git a/include/PgSQL_Connection.h b/include/PgSQL_Connection.h index 8f221f382..46a6b7024 100644 --- a/include/PgSQL_Connection.h +++ b/include/PgSQL_Connection.h @@ -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(); diff --git a/lib/PgSQL_Connection.cpp b/lib/PgSQL_Connection.cpp index f5c42897c..a9feda366 100644 --- a/lib/PgSQL_Connection.cpp +++ b/lib/PgSQL_Connection.cpp @@ -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); } }