Skip to content

Commit b7c7561

Browse files
bluehat974carlopi
authored andcommitted
Fix send() infinite loop on detached worker
1 parent c3caa42 commit b7c7561

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

packages/duckdb-wasm/src/parallel/async_bindings.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -318,6 +318,11 @@ export class AsyncDuckDB implements AsyncDuckDBBindings {
318318
this._pendingRequests.clear();
319319
}
320320

321+
/** Is in detached state, no worker defined */
322+
public isDetached(): boolean {
323+
return !this._worker;
324+
}
325+
321326
/** Reset the duckdb */
322327
public async reset(): Promise<null> {
323328
const task = new WorkerTask<WorkerRequestType.RESET, null, null>(WorkerRequestType.RESET, null);

packages/duckdb-wasm/src/parallel/async_connection.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,11 @@ export class AsyncDuckDBConnection {
6262
});
6363
let header = await this._bindings.startPendingQuery(this._conn, text, allowStreamResult);
6464
while (header == null) {
65+
// Avoid infinite loop on detached state
66+
if (this._bindings.isDetached()) {
67+
console.error('cannot send a message since the worker is not set!');
68+
return undefined as any;
69+
}
6570
header = await this._bindings.pollPendingQuery(this._conn);
6671
}
6772
const iter = new AsyncResultStreamIterator(this._bindings, this._conn, header);

0 commit comments

Comments
 (0)