From 7c14aeaf411a3ad29e16bc0fad07566f79fbb013 Mon Sep 17 00:00:00 2001 From: Timothy Messier Date: Fri, 19 Apr 2024 13:40:42 -0400 Subject: [PATCH] fix(session): Use active transaction (#4592) When closing orphaned connections and checking if a session is not active, the repository was opening a transaction, but then calling the original reader instead of using the reader/writer from the transaction. This would result in a transaction being opend, then a separate transaction being used to run the query, and finally the original transaction would commit without any statements being executed. Co-authored-by: Sorawis Nilparuk (Bo) --- internal/session/repository_connection.go | 4 ++-- internal/session/repository_session.go | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/internal/session/repository_connection.go b/internal/session/repository_connection.go index 11a61e7904..34975d995b 100644 --- a/internal/session/repository_connection.go +++ b/internal/session/repository_connection.go @@ -416,8 +416,8 @@ func (r *ConnectionRepository) closeOrphanedConnections(ctx context.Context, wor ctx, db.StdRetryCnt, db.ExpBackoff{}, - func(reader db.Reader, w db.Writer) error { - rows, err := r.reader.Query(ctx, fmt.Sprintf(orphanedConnectionsCte, notInClause), args) + func(_ db.Reader, w db.Writer) error { + rows, err := w.Query(ctx, fmt.Sprintf(orphanedConnectionsCte, notInClause), args) if err != nil { return errors.Wrap(ctx, err, op) } diff --git a/internal/session/repository_session.go b/internal/session/repository_session.go index 042e96bccb..ccc708b3d8 100644 --- a/internal/session/repository_session.go +++ b/internal/session/repository_session.go @@ -830,9 +830,9 @@ func (r *Repository) CheckIfNotActive(ctx context.Context, reportedSessions []st ctx, db.StdRetryCnt, db.ExpBackoff{}, - func(reader db.Reader, w db.Writer) error { + func(reader db.Reader, _ db.Writer) error { var states []*State - err := r.reader.SearchWhere(ctx, &states, "end_time is null and session_id in (?)", []any{reportedSessions}) + err := reader.SearchWhere(ctx, &states, "end_time is null and session_id in (?)", []any{reportedSessions}) if err != nil { return errors.Wrap(ctx, err, op) }