RHINENG-27056: fix waitForSessionClosed query#2235
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.
| if err != nil { | ||
| log.Info(err) | ||
| utils.LogError("err", err.Error(), "failed to check app database sessions") | ||
| time.Sleep(time.Second) | ||
| continue |
There was a problem hiding this comment.
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.
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #2235 +/- ##
=======================================
Coverage 59.06% 59.06%
=======================================
Files 138 138
Lines 8848 8848
=======================================
Hits 5226 5226
Misses 3076 3076
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:
|
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: