fix: make sure old query stream doesn't block on close #5730
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.
Description
Fixes #5724
The ksqlDB CLI currently uses the old query streaming API at /query.
When terminating a query from the CLI, the connection is closed. The close is detected in the QueryStreamWriter poll loop which causes it to flush the OutputStream. This causes a write to be called on the underlying ResponseOutputStream, but because the channel isn't available for writing writeQueueFull() returns true and the thread is blocked until it times out (previously 60 seconds). This means that, previously, if you start and terminate queries quite rapidly, it takes 60 seconds for each ones state to be cleared up on the server.
This PR changes the blocking in ResponseOutputStream so it can return more quickly if the stream is closed. It also changes the blocking timeout to 10 minutes, and it changes the server idle timeout to 10 minutes.
The old query endpoint had been migrated as is from Jetty to Vert.x. The old code is somewhat complex and this bug arose in the mapping from the synchronous approach taken in the old implementation and the Vert.x asynchronous APIs.
I'd recommend that the ksqlDB is refactored to use the new query streaming API (e.g. via the new Java client) which does not have these issues, and the old /query API is deprecated.
Testing done
Non functional change.
Manually verified.
Reviewer checklist