Skip to content

Commit 2717b7a

Browse files
Code cleanup
1 parent ffeec7e commit 2717b7a

File tree

2 files changed

+13
-6
lines changed

2 files changed

+13
-6
lines changed

packages/web/src/db/adapters/AsyncDatabaseConnection.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,15 @@ export type OnTableChangeCallback = (event: BatchedUpdateNotification) => void;
2525
export interface AsyncDatabaseConnection<Config extends ResolvedWebSQLOpenOptions = ResolvedWebSQLOpenOptions> {
2626
init(): Promise<void>;
2727
close(): Promise<void>;
28+
/**
29+
* Marks the connection as in-use by a certain actor.
30+
* @returns A hold ID which can be used to release the hold.
31+
*/
2832
markHold(): Promise<string>;
33+
/**
34+
* Releases a hold on the connection.
35+
* @param holdId The hold ID to release.
36+
*/
2937
releaseHold(holdId: string): Promise<void>;
3038
execute(sql: string, params?: any[]): Promise<ProxiedQueryResult>;
3139
executeRaw(sql: string, params?: any[]): Promise<any[][]>;

packages/web/src/worker/db/SharedWASQLiteConnection.ts

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,11 @@ export class SharedWASQLiteConnection implements AsyncDatabaseConnection {
8080
clientIds.delete(clientId);
8181

8282
if (this.activeHoldId) {
83-
/**
84-
* The hold hasn't been released, but we're closing now.
85-
* We can proactively cleanup and release the hold.
86-
*/
87-
await this.connection.execute('ROLLBACK').catch(() => {});
88-
await this.connection.releaseHold(this.activeHoldId).catch(() => {});
83+
// We can't cleanup here since we're not in a lock context.
84+
// The cleanup will occur once a new hold is acquired.
85+
this.logger.info(
86+
`Hold ${this.activeHoldId} was still active when the connection was closed. Cleanup will occur once a new hold is acquired.`
87+
);
8988
}
9089

9190
if (clientIds.size == 0) {

0 commit comments

Comments
 (0)