Skip to content

Commit 86c07c9

Browse files
committed
postgres: Make dut more robust against broken connections.
1 parent ad81dab commit 86c07c9

File tree

1 file changed

+13
-13
lines changed

1 file changed

+13
-13
lines changed

postgres.cc

+13-13
Original file line numberDiff line numberDiff line change
@@ -24,25 +24,25 @@ dut_pqxx::dut_pqxx(std::string conninfo)
2424

2525
void dut_pqxx::test(const std::string &stmt)
2626
{
27-
if (reset_gucs) {
27+
try {
2828

29-
if(!c.is_open())
30-
c.activate();
29+
if (reset_gucs) {
3130

32-
pqxx::work w(c);
31+
if(!c.is_open())
32+
c.activate();
3333

34-
w.exec("set statement_timeout to '1s';"
35-
"set client_min_messages to 'ERROR';"
36-
"set application_name to '" PACKAGE "::dut';");
37-
w.commit();
38-
reset_gucs = false;
39-
}
34+
pqxx::work w(c);
4035

41-
pqxx::work w(c);
42-
try {
36+
w.exec("set statement_timeout to '1s';"
37+
"set client_min_messages to 'ERROR';"
38+
"set application_name to '" PACKAGE "::dut';");
39+
w.commit();
40+
reset_gucs = false;
41+
}
42+
43+
pqxx::work w(c);
4344
w.exec(stmt.c_str());
4445
} catch (const pqxx::failure &e) {
45-
w.abort();
4646
if ((dynamic_cast<const pqxx::broken_connection *>(&e))) {
4747
/* re-throw to outer loop to recover session. */
4848
reset_gucs = true;

0 commit comments

Comments
 (0)