Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

@jtbeach
Copy link

@jtbeach jtbeach commented Nov 25, 2025

This is an alternative to #4468 that works across dialects.

From the original PR:

However, in transaction mode, no cleanup function is returned, which means that when Commit() or Rollback() is called on the ent.Tx and the connection is returned to the pool, set sql vars persist and leak so that the next user of that pooled connection will still see those sql vars set.

Since many applications (and the guide here suggests: https://entgo.io/docs/migration/row-level-security/) use sql vars to implement RLS, it seems like a footgun that these vars persist

This PR make sure that sql vars are reset every single statement inside a transaction and works across database types (doesn't rely on PostgreSQL-specific SET LOCAL). This is also more correct if users are setting different sqlvars across different statement inside their transaction (edge case).

The negative aspect of this PR is that we will issue RESET statements after every statement in a query (but only if sqlvars are actually used)

@jtbeach jtbeach changed the title Fix sqlvars link in transactions Don't leak session vars back to connection pool on tx commit/rollback (cross-dialect alternative) Nov 25, 2025
@jtbeach jtbeach force-pushed the set-local-alternative branch from 6c11c30 to b0f87d3 Compare November 25, 2025 20:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant