fix(pgsql): guard monitor task removal against self-move - #6039
fix(pgsql): guard monitor task removal against self-move#6039Snehil-Shah wants to merge 1 commit into
Conversation
Signed-off-by: Snehil Shah <snehilshah.989@gmail.com>
Code Review ✅ ApprovedGuards PostgreSQL monitor task removal against self-move operations to prevent runtime crashes when compiled with libc++. No issues found. OptionsAuto-apply is off → Gitar will not commit updates to this branch. Comment with these commands to change the behavior for this request:
Was this helpful? React with 👍 / 👎 | Gitar |
|
📝 WalkthroughWalkthrough
ChangesTask removal handling
Estimated code review effort: 1 (Trivial) | ~5 minutes Suggested reviewers: Poem
🚥 Pre-merge checks | ✅ 4 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (4 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
| if (idx >= task_poll.size) { | ||
| proxy_error("Received invalid task index idx=%zu\n", idx); |
There was a problem hiding this comment.
Drive-by correctness fix. idx is unsigned so the second check was a no-op, and idx == task_poll.size is also an invalid task index.
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.
Inline comments:
In `@lib/PgSQL_Monitor.cpp`:
- Around line 1273-1276: In the invalid-index guard around task_poll access,
make the function return unconditionally after proxy_error; retain assert(0)
only as diagnostic if desired, but ensure execution cannot reach writes to
task_poll.fds or task_poll.tasks or the task_poll.size decrement when idx >=
task_poll.size.
🪄 Autofix
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro Plus
Run ID: 2f0cc634-90f3-4c3e-80c2-aad604651a7b
📒 Files selected for processing (1)
lib/PgSQL_Monitor.cpp
📜 Review details
⏰ Context from checks skipped due to timeout. (1)
- GitHub Check: cubic · AI code reviewer
🧰 Additional context used
📓 Path-based instructions (1)
**/*.{cpp,h,hpp}
📄 CodeRabbit inference engine (CLAUDE.md)
**/*.{cpp,h,hpp}: Class names must usePascalCasewith protocol prefixes such asMySQL_,PgSQL_, andProxySQL_.
Member variables must usesnake_case.
Constants and macros must useUPPER_SNAKE_CASE.
Use C++17, and gate conditional code with#ifdef PROXYSQL31,#ifdef PROXYSQL40,#ifdef PROXYSQLFFTO,#ifdef PROXYSQLTSDB, and#ifdef PROXYSQLCLICKHOUSE;PROXYSQLGENAImust not guard core code outsideplugins/genai/.
Consider performance implications when changing hot paths or other performance-critical code.
Use RAII for resource management and jemalloc for allocation.
Use pthread mutexes for synchronization andstd::atomic<>for counters.
Files:
lib/PgSQL_Monitor.cpp
There was a problem hiding this comment.
All reported issues were addressed across 1 file
Reply with feedback, questions, or to request a fix.
Fix all with cubic | Re-trigger cubic
|
Thank you @Snehil-Shah for tracking down and fixing this libc++ crash. I reviewed the change and found no actionable correctness issues. The corrected bounds check and the guard against moving the last task onto itself both look sound. A focused libc++ regression test covering last-slot and non-last-slot removal would be useful future protection, but I do not consider it merge-blocking. Looks good from the code-review side. Thanks again for the contribution. |



The build crashes at runtime when linked with
libc++due to a self-std::moveoperation, which is unspecified behavior. It happens to work in our favour withlibstdc++, but crashes withlibc++.Ref: https://cplusplus.github.io/LWG/issue2839
Summary by cubic
Prevents a crash in
libc++builds by guarding against a self-move in PgSQL monitor task removal. Also fixes index validation and improves the error log.std::move).idx >= size; fix log text and use%zu.Written for commit 1d70298. Summary will update on new commits.
Summary by CodeRabbit