Skip to content

Commit 7551ec6

Browse files
authored
Merge pull request #5789 from sysown/v3.0_fix_pgsql-set_statement_test_5788
fix(test): pgsql-set_statement_test-t log race (#5788)
2 parents 141c3e8 + a62b6a2 commit 7551ec6

1 file changed

Lines changed: 15 additions & 1 deletion

File tree

test/tap/tests/pgsql-set_statement_test-t.cpp

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,9 +74,23 @@ struct TestCase {
7474
};
7575

7676
std::fstream f_proxysql_log{};
77+
PGConnPtr admin_conn{nullptr, &PQfinish};
7778

7879
bool check_logs_for_command(const std::string& command_regex) {
79-
const auto& [_, cmd_lines] { get_matching_lines(f_proxysql_log, command_regex) };
80+
// Issue #5788: log-scrape race. PROXYSQL FLUSH LOGS over a persistent
81+
// Admin connection fences in-flight log writes before we scan, and
82+
// clearing eofbit lets getline() read bytes appended since the last
83+
// scan (sticky eofbit was the root cause). Single scan, no polling.
84+
if (!admin_conn || PQstatus(admin_conn.get()) != CONNECTION_OK) {
85+
admin_conn = createNewConnection(ADMIN);
86+
}
87+
if (admin_conn) {
88+
PGresult* res = PQexec(admin_conn.get(), "PROXYSQL FLUSH LOGS");
89+
if (res) PQclear(res);
90+
}
91+
92+
f_proxysql_log.clear(f_proxysql_log.rdstate() & ~std::ios_base::eofbit & ~std::ios_base::failbit);
93+
const auto& [_, cmd_lines] = get_matching_lines(f_proxysql_log, command_regex);
8094
return !cmd_lines.empty();
8195
}
8296

0 commit comments

Comments
 (0)