Implement Backend Query Cancellation and Backend Termination for PostgreSQL#5137
Conversation
Add support for PostgreSQL query cancellation and backend termination features to allow clients to cancel long-running queries and terminate connections through the standard PostgreSQL protocol. Features implemented: - Intercept pg_backend_pid() queries and return ProxySQL session thread ID - Intercept pg_terminate_backend() to terminate client connections asynchronously - Intercept pg_cancel_backend() to cancel queries on backend connections - Support Cancel Request protocol via separate connection with PID and secret key validation - Return BackendKeyData message on successful authentication with session thread ID and unique cancel secret key This enables clients to use standard PostgreSQL cancellation mechanisms (pg_cancel_backend, pg_terminate_backend, and Cancel Request protocol) while ProxySQL maintains proper session isolation and maps client requests to appropriate backend connections.
Summary of ChangesHello @rahim-kanji, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed! This pull request significantly enhances ProxySQL's PostgreSQL support by introducing robust mechanisms for backend query cancellation and connection termination. It addresses a long-standing issue by allowing users to interrupt long-running queries or forcibly close unresponsive connections, improving operational control and stability. The changes involve deep integration with PostgreSQL's native protocols, refactoring internal session management, and extending the admin interface to support these new capabilities. Highlights
Using Gemini Code AssistThe full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips. Invoking Gemini You can request assistance from Gemini at any point by creating a comment using either
Customization To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a Limitations & Feedback Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension. Footnotes
|
There was a problem hiding this comment.
Code Review
This pull request introduces a significant and valuable feature: the ability to cancel running queries and terminate backend connections for PostgreSQL. The implementation is comprehensive, touching multiple parts of the codebase to handle signaling, authentication of requests, and execution of the cancellation/termination. The refactoring of argument-passing structures and the use of modern C++ features like std::unique_ptr are commendable improvements.
My review focuses on a critical security vulnerability in the fallback key generation mechanism and a suggestion to improve code maintainability by reducing duplication. Addressing these points will further strengthen the implementation.
Centralize escaping/formatting of connection parameters (key='value'). Replace duplicate escape/append/free sequences in connect_start and PgSQL_backend_kill_thread.
|


Closes #5136