Skip to content

Commit b29c682

Browse files
committed
clean state between clients session
1 parent 3e24ea7 commit b29c682

File tree

1 file changed

+11
-1
lines changed

1 file changed

+11
-1
lines changed

apps/postgres-new/components/app-provider.tsx

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,17 @@ export default function AppProvider({ children }: AppProps) {
138138
if (isStartupMessage(message)) {
139139
const parameters = parseStartupMessage(message)
140140
if ('client_ip' in parameters) {
141-
setConnectedClientIp(parameters.client_ip === '' ? null : parameters.client_ip)
141+
// client disconnected
142+
if (parameters.client_ip === '') {
143+
setConnectedClientIp(null)
144+
// we ensure we're not in a transaction block first
145+
await db.sql`rollback;`.catch()
146+
// we clean the session state, see: https://www.pgbouncer.org/faq.html#how-to-use-prepared-statements-with-session-pooling
147+
// we do this to avoid having old prepared statements in the session
148+
await db.sql`discard all;`
149+
} else {
150+
setConnectedClientIp(parameters.client_ip)
151+
}
142152
}
143153
return
144154
}

0 commit comments

Comments
 (0)