Skip to content

Commit b1bf82d

Browse files
authored
Enable awaitWriteFinish for the db config file watcher (#1872)
1 parent 602289e commit b1bf82d

1 file changed

Lines changed: 14 additions & 3 deletions

File tree

extensions/ql-vscode/src/databases/config/db-config-store.ts

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -166,9 +166,20 @@ export class DbConfigStore extends DisposableObject {
166166
}
167167

168168
private watchConfig(): void {
169-
this.configWatcher = chokidar.watch(this.configPath).on("change", () => {
170-
this.readConfigSync();
171-
});
169+
this.configWatcher = chokidar
170+
.watch(this.configPath, {
171+
// In some cases, change events are emitted while the file is still
172+
// being written. The awaitWriteFinish option tells the watcher to
173+
// poll the file size, holding its add and change events until the size
174+
// does not change for a configurable amount of time. We set that time
175+
// to 1 second, but it may need to be adjusted if there are issues.
176+
awaitWriteFinish: {
177+
stabilityThreshold: 1000,
178+
},
179+
})
180+
.on("change", () => {
181+
this.readConfigSync();
182+
});
172183
}
173184

174185
private createEmptyConfig(): DbConfig {

0 commit comments

Comments
 (0)