fix: Implement robust watchdog for stream query timeouts#281
Merged
Conversation
This commit resolves a critical issue where streaming queries would crash when a client-side `query_timeout` was configured. The root cause is a known bug in `node-postgres` (issue #1860) that mishandles timeouts for streamable query objects that lack a callback property. The fix introduces a client-side "time-to-first-chunk" watchdog that replaces the problematic built-in timeout mechanism for streams: 1. **Watchdog for First Chunk**: A timer is now set based on the `client.query_timeout` or `connectionParameters.query_timeout`. This timer is cleared as soon as the first chunk of data is received, ensuring that long-running streams that are actively sending data do not time out. 2. **Clear Error Messaging**: If a timeout occurs, the stream is destroyed with a detailed error message that correctly identifies whether the timeout was triggered by a client-level or connection-level setting. 3. **Refactoring**: The watchdog logic has been extracted into a reusable `setupStreamWatchdog` helper function to improve code clarity and remove duplication. 4. **Comprehensive Testing**: Added a suite of tests for stream timeouts, including positive cases, and negative cases for both pooled and direct client connections to ensure the watchdog behaves as expected.
Owner
Author
|
🎉 This PR is included in version 3.48.2 🎉 The release is available on: Your semantic-release bot 📦🚀 |
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 commit resolves a critical issue where streaming queries would crash when a client-side
query_timeoutwas configured. The root cause is a known bug innode-postgres(issue #1860) that mishandles timeouts for streamable query objects that lack a callback property.The fix introduces a client-side "time-to-first-chunk" watchdog that replaces the problematic built-in timeout mechanism for streams:
Watchdog for First Chunk: A timer is now set based on the
client.query_timeoutorconnectionParameters.query_timeout. This timer is cleared as soon as the first chunk of data is received, ensuring that long-running streams that are actively sending data do not time out.Clear Error Messaging: If a timeout occurs, the stream is destroyed with a detailed error message that correctly identifies whether the timeout was triggered by a client-level or connection-level setting.
Refactoring: The watchdog logic has been extracted into a reusable
setupStreamWatchdoghelper function to improve code clarity and remove duplication.Comprehensive Testing: Added a suite of tests for stream timeouts, including positive cases, and negative cases for both pooled and direct client connections to ensure the watchdog behaves as expected.