Skip to content

Commit 0aa6474

Browse files
fix(proxy-capture): wrap deletePathBasedSessions DELETEs in transaction
deletePathBasedSessions executes DELETE FROM capture_events and DELETE FROM capture_sessions as separate auto-commit statements. A crash between them would leave the two tables inconsistent. The sibling method deleteSessions() already uses runSqliteImmediateTransactionSync. Wrap both DELETEs in deletePathBasedSessions the same way. Fixes #98959 Co-Authored-By: Claude <[email protected]>
1 parent d32c4cf commit 0aa6474

1 file changed

Lines changed: 15 additions & 15 deletions

File tree

‎src/proxy-capture/store.sqlite.ts‎

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -50,8 +50,7 @@ function isInMemoryDatabasePath(dbPath: string): boolean {
5050
const fragmentIndex = dbPath.indexOf("#");
5151
const uriWithoutFragment = fragmentIndex === -1 ? dbPath : dbPath.slice(0, fragmentIndex);
5252
const queryIndex = uriWithoutFragment.indexOf("?");
53-
const uriPath =
54-
queryIndex === -1 ? uriWithoutFragment : uriWithoutFragment.slice(0, queryIndex);
53+
const uriPath = queryIndex === -1 ? uriWithoutFragment : uriWithoutFragment.slice(0, queryIndex);
5554
try {
5655
if (decodeURIComponent(uriPath.slice("file:".length)) === ":memory:") {
5756
return true;
@@ -743,10 +742,14 @@ class DebugProxyCaptureStoreImpl {
743742
)
744743
.get(...sessionIds) as { count: number }
745744
).count ?? 0;
746-
this.db.prepare(`DELETE FROM capture_events WHERE session_id IN (${placeholders})`).run(
747-
...sessionIds,
748-
);
749-
this.db.prepare(`DELETE FROM capture_sessions WHERE id IN (${placeholders})`).run(...sessionIds);
745+
runSqliteImmediateTransactionSync(this.db, () => {
746+
this.db
747+
.prepare(`DELETE FROM capture_events WHERE session_id IN (${placeholders})`)
748+
.run(...sessionIds);
749+
this.db
750+
.prepare(`DELETE FROM capture_sessions WHERE id IN (${placeholders})`)
751+
.run(...sessionIds);
752+
});
750753
const candidateBlobIds = blobRows
751754
.map((row) => row.blobId?.trim())
752755
.filter((blobId): blobId is string => Boolean(blobId));
@@ -783,10 +786,7 @@ class DebugProxyCaptureStoreImpl {
783786
}
784787

785788
export type DebugProxyCaptureStore = Omit<DebugProxyCaptureStoreImpl, "persistPayload"> & {
786-
persistPayload(
787-
data: Buffer,
788-
contentType?: string,
789-
): CaptureBlobRecord | SharedCaptureBlobRecord;
789+
persistPayload(data: Buffer, contentType?: string): CaptureBlobRecord | SharedCaptureBlobRecord;
790790
};
791791

792792
export type LegacyDebugProxyCaptureStore = Omit<DebugProxyCaptureStoreImpl, "persistPayload"> & {
@@ -860,7 +860,10 @@ export function closeDebugProxyCaptureStore(): void {
860860

861861
// Lease API keeps one cached capture-store wrapper alive across related
862862
// operations, then releases it without closing the shared state database.
863-
export function acquireDebugProxyCaptureStore(dbPath: string, blobDir: string): {
863+
export function acquireDebugProxyCaptureStore(
864+
dbPath: string,
865+
blobDir: string,
866+
): {
864867
store: LegacyDebugProxyCaptureStore;
865868
release: () => void;
866869
};
@@ -905,10 +908,7 @@ export function acquireDebugProxyCaptureStore(
905908

906909
export function persistEventPayload(
907910
store: {
908-
persistPayload(
909-
data: Buffer,
910-
contentType?: string,
911-
): CaptureBlobRecord | SharedCaptureBlobRecord;
911+
persistPayload(data: Buffer, contentType?: string): CaptureBlobRecord | SharedCaptureBlobRecord;
912912
},
913913
params: { data?: Buffer | string | null; contentType?: string; previewLimit?: number },
914914
): { dataText?: string; dataBlobId?: string; dataSha256?: string } {

0 commit comments

Comments
 (0)