diff --git a/src/server.rs b/src/server.rs index 152f0524..8f0ece99 100644 --- a/src/server.rs +++ b/src/server.rs @@ -963,6 +963,7 @@ impl Server { if self.needs_cleanup { warn!("Server returned with session state altered, discarding state"); self.query("DISCARD ALL").await?; + self.query("RESET ROLE").await?; self.needs_cleanup = false; } diff --git a/tests/ruby/misc_spec.rb b/tests/ruby/misc_spec.rb index 1a04c5d6..e4d6f6fb 100644 --- a/tests/ruby/misc_spec.rb +++ b/tests/ruby/misc_spec.rb @@ -241,6 +241,18 @@ expect(processes.primary.count_query("DISCARD ALL")).to eq(10) end + + it "Resets server roles correctly" do + 10.times do + conn = PG::connect(processes.pgcat.connection_string("sharded_db", "sharding_user")) + conn.async_exec("SET SERVER ROLE to 'primary'") + conn.async_exec("SELECT 1") + conn.async_exec("SET statement_timeout to 5000") + conn.close + end + + expect(processes.primary.count_query("RESET ROLE")).to eq(10) + end end context "transaction mode" do