RHINENG-27056: fix waitForSessionClosed query#2235
Merged
TenSt merged 1 commit intoJun 23, 2026
Merged
Conversation
Reviewer's GuideRefactors the session-wait logic to use a safe, testable query helper that relies on lib/pq ANY($1), changes error handling in waitForSessionClosed to fail closed with retries on query errors, and adds tests covering error, empty, and active-session cases. File-Level Changes
Tips and commandsInteracting with Sourcery
Customizing Your ExperienceAccess your dashboard to:
Getting Help
|
There was a problem hiding this comment.
Hey - I've found 1 issue, and left some high level feedback:
- In
waitForSessionClosed, a persistent query failure will now cause an endless loop with a log+sleep every second; consider adding a max retry count, timeout, or contextual cancellation so the function can fail explicitly instead of potentially hanging indefinitely on a broken DB connection.
Prompt for AI Agents
Please address the comments from this code review:
## Overall Comments
- In `waitForSessionClosed`, a persistent query failure will now cause an endless loop with a log+sleep every second; consider adding a max retry count, timeout, or contextual cancellation so the function can fail explicitly instead of potentially hanging indefinitely on a broken DB connection.
## Individual Comments
### Comment 1
<location path="database_admin/update.go" line_range="64-67" />
<code_context>
- "usename IN (?) LIMIT 30;", lockUsers,
- ).Scan(&session)
+ session, found, err := findActiveAppSession(db)
if err != nil {
- log.Info(err)
+ utils.LogError("err", err.Error(), "failed to check app database sessions")
+ time.Sleep(time.Second)
+ continue
}
- if session == "" {
</code_context>
<issue_to_address>
**issue (bug_risk):** Loop on error without a termination condition may mask persistent failures.
If `findActiveAppSession` keeps failing (e.g., due to permissions on `pg_stat_activity` or a persistent network issue), this loop will sleep and retry forever, causing the migration to hang on non-recoverable errors. Please add a max retry/timeout mechanism or surface the error after a threshold so the failure is explicit instead of an infinite wait.
</issue_to_address>Help me be more useful! Please click 👍 or 👎 on each comment and I'll use the feedback to improve your reviews.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2235 +/- ##
==========================================
- Coverage 59.06% 59.04% -0.03%
==========================================
Files 138 138
Lines 8848 8848
==========================================
- Hits 5226 5224 -2
- Misses 3076 3078 +2
Partials 546 546
Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
7a6971a to
a705a94
Compare
a705a94 to
b7c5b92
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR:
waitForSessionClosedto use lib/pqANY($1)and fail closed on query errorsIN (?)withusename = ANY($1)andpq.Array(lockUsers)for rawdatabase/sqlfindActiveAppSession()so session lookup is testable and errors are handled explicitlymanagersession detectionTest steps locally:
docker compose -f docker-compose.test.yml run --rm test ./scripts/go_test.sh './database_admin'(with DB already migrated)Summary by Sourcery
Ensure database session checks for application lock users are robust against query errors and correctly detect active sessions.
Bug Fixes:
Enhancements:
Tests: