Skip to content

Commit 8feb992

Browse files
committed
remove snapshot APIs that deadlock libuv thread pool
1 parent c75479f commit 8feb992

File tree

3 files changed

+2
-46
lines changed

3 files changed

+2
-46
lines changed

apps/code/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@
123123
"@opentelemetry/resources": "^2.5.0",
124124
"@opentelemetry/sdk-logs": "^0.208.0",
125125
"@opentelemetry/semantic-conventions": "^1.39.0",
126-
"@parcel/watcher": "^2.5.1",
126+
"@parcel/watcher": "^2.5.6",
127127
"@phosphor-icons/react": "^2.1.10",
128128
"@posthog/agent": "workspace:*",
129129
"@posthog/electron-trpc": "workspace:*",

apps/code/src/main/services/file-watcher/service.ts

Lines changed: 0 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { existsSync } from "node:fs";
22
import fs from "node:fs/promises";
33
import path from "node:path";
44
import * as watcher from "@parcel/watcher";
5-
import { app } from "electron";
65
import { inject, injectable } from "inversify";
76
import { MAIN_TOKENS } from "../../di/tokens";
87
import { logger } from "../../utils/logger";
@@ -70,9 +69,6 @@ export class FileWatcherService extends TypedEventEmitter<FileWatcherEvents> {
7069
async startWatching(repoPath: string): Promise<void> {
7170
if (this.watchers.has(repoPath)) return;
7271

73-
await fs.mkdir(this.snapshotsDir, { recursive: true });
74-
await this.emitChangesSinceSnapshot(repoPath);
75-
7672
const pending: PendingChanges = {
7773
dirs: new Set(),
7874
files: new Set(),
@@ -107,53 +103,13 @@ export class FileWatcherService extends TypedEventEmitter<FileWatcherEvents> {
107103
if (!w) return;
108104

109105
if (w.pending.timer) clearTimeout(w.pending.timer);
110-
await this.saveSnapshot(repoPath);
111106
await this.watcherRegistry.unregister(w.filesId);
112107
for (const gitId of w.gitIds) {
113108
await this.watcherRegistry.unregister(gitId);
114109
}
115110
this.watchers.delete(repoPath);
116111
}
117112

118-
private get snapshotsDir(): string {
119-
return path.join(app.getPath("userData"), "snapshots");
120-
}
121-
122-
private snapshotPath(repoPath: string): string {
123-
return path.join(
124-
this.snapshotsDir,
125-
`${Buffer.from(repoPath).toString("base64url")}.snapshot`,
126-
);
127-
}
128-
129-
private async saveSnapshot(repoPath: string): Promise<void> {
130-
try {
131-
await watcher.writeSnapshot(repoPath, this.snapshotPath(repoPath), {
132-
ignore: IGNORE_PATTERNS,
133-
});
134-
} catch (error) {
135-
log.error("Failed to write snapshot:", error);
136-
}
137-
}
138-
139-
private async emitChangesSinceSnapshot(repoPath: string): Promise<void> {
140-
const snapshotPath = this.snapshotPath(repoPath);
141-
try {
142-
await fs.access(snapshotPath);
143-
} catch {
144-
return;
145-
}
146-
147-
const events = await watcher.getEventsSince(repoPath, snapshotPath, {
148-
ignore: IGNORE_PATTERNS,
149-
});
150-
151-
const affectedDirs = new Set(events.map((e) => path.dirname(e.path)));
152-
for (const dirPath of affectedDirs) {
153-
this.emit(FileWatcherEvent.DirectoryChanged, { repoPath, dirPath });
154-
}
155-
}
156-
157113
private async watchFiles(
158114
repoPath: string,
159115
pending: PendingChanges,

pnpm-lock.yaml

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)