Skip to content

Commit 014f600

Browse files
committed
fix: Retry with fresh connection on BrokenPipe for single queries as well
1 parent e452d8a commit 014f600

1 file changed

Lines changed: 12 additions & 1 deletion

File tree

client.ts

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,18 @@ export abstract class QueryClient {
274274
_query: Query<ResultType.OBJECT>,
275275
): Promise<QueryObjectResult<T>>;
276276
async #executeQuery(query: Query<ResultType>): Promise<QueryResult> {
277-
return await this.#connection.query(query);
277+
try {
278+
return await this.#connection.query(query);
279+
} catch (e) {
280+
if (e instanceof Deno.errors.BrokenPipe) {
281+
// Retry once with fresh connection, if connection was dropped by server since last query
282+
await this.closeConnection();
283+
await this.connect();
284+
return await this.#connection.query(query);
285+
} else {
286+
throw e;
287+
}
288+
}
278289
}
279290

280291
/**

0 commit comments

Comments
 (0)