1
Fork 0
mirror of https://github.com/RGBCube/serenity synced 2025-05-14 12:05:00 +00:00

LibSQL+SQLServer: Inform SQLServer when the client has processed results

The architecture of SQLServer is currently such that it sends results
over IPC one row at a time. After the rows are exhausted, it sends a
completion IPC. However, it does not wait for the client to finish
processing a row before sending another row or the completion signal.

This can result in clients hanging if the completion comes in while a
row is being processed. At least in the case of WebView::Database, the
result is that the completion signal is dropped, and the browser then
hangs forever waiting for that signal (after it finishes processing the
row).

This patch makes SQLServer asynchronously wait for the client to tell it
that the row has been processed and the next row (or completion) may be
sent. We repurpose the `m_ongoing_executions` in SQLStatement for this
purpose (this member was oddly being written to, but otherwise unused).
This commit is contained in:
Timothy Flynn 2024-01-09 19:32:44 -05:00 committed by Andreas Kling
parent df5451a889
commit 1205d39fc3
6 changed files with 54 additions and 29 deletions

View file

@ -6,6 +6,7 @@
*/
#include <AK/ByteString.h>
#include <AK/ScopeGuard.h>
#include <AK/String.h>
#include <LibSQL/SQLClient.h>
@ -202,6 +203,8 @@ void SQLClient::execution_error(u64 statement_id, u64 execution_id, SQLErrorCode
void SQLClient::next_result(u64 statement_id, u64 execution_id, Vector<Value> const& row)
{
ScopeGuard guard { [&]() { async_ready_for_next_result(statement_id, execution_id); } };
if (!on_next_result) {
StringBuilder builder;
builder.join(", "sv, row, "\"{}\""sv);