@@ -95,7 +95,7 @@ func (db *TokenLockStore) GetSchema() string {
9595 tx_id TEXT NOT NULL,
9696 idx INT NOT NULL,
9797 consumer_tx_id TEXT NOT NULL,
98- created_at TIMESTAMP NOT NULL,
98+ created_at TIMESTAMPTZ NOT NULL,
9999 PRIMARY KEY(tx_id, idx),
100100 FOREIGN KEY (tx_id, idx) REFERENCES %s
101101 );
@@ -125,7 +125,10 @@ func IsExpiredToken(tokenRequests, tokenLocks common3.Table, leaseExpiry time.Du
125125// whether the lock is still live. The condition is correlated rather than a
126126// partial-key IN on tx_id, so cleanup removes only the matching (tx_id, idx) rows
127127// and leaves the other indices of the same transaction locked. See #2018.
128- func IsStaleLock (tokenLocks , tokenRequests common3.Table , leaseExpiry time.Duration ) cond.Condition {
128+ //
129+ // The argument order matches IsExpiredToken (tokenRequests first, tokenLocks second)
130+ // so a swapped call is immediately visible and consistent across this file.
131+ func IsStaleLock (tokenRequests , tokenLocks common3.Table , leaseExpiry time.Duration ) cond.Condition {
129132 return cond .Or (
130133 cond .OlderThan (tokenLocks .Field ("created_at" ), leaseExpiry ),
131134 cond .Exists (
@@ -143,12 +146,13 @@ func IsStaleLock(tokenLocks, tokenRequests common3.Table, leaseExpiry time.Durat
143146// Cleanup releases the stale token locks: those whose consuming transaction is
144147// Deleted or Orphan, and those whose lease is older than leaseExpiry. Only the
145148// affected (tx_id, idx) rows are deleted. The same statement is used by every SQL
146- // backend, so lock lifetime does not depend on the driver in use.
149+ // backend. created_at is declared TIMESTAMPTZ so the comparison with the
150+ // database-side NOW() expression is always timezone-consistent on Postgres.
147151func (db * TokenLockStore ) Cleanup (ctx context.Context , leaseExpiry time.Duration ) error {
148152 tokenLocks , tokenRequests := q .Table (db .Table .TokenLocks ), q .Table (db .Table .Requests )
149153
150154 query , args := q .DeleteFrom (db .Table .TokenLocks ).
151- Where (IsStaleLock (tokenLocks , tokenRequests , leaseExpiry )).
155+ Where (IsStaleLock (tokenRequests , tokenLocks , leaseExpiry )).
152156 Format (db .ci )
153157
154158 db .Logger .Debug (query , args )
0 commit comments