Skip to content

Commit c8fb5ad

Browse files
stop reading before writing stores (eclipse-theia#12717)
The merging of on disk values using `deepmerge` is bogus. Instead we'll completely overwrite the file. This should be fine as the `PluginsKeyValueStorage` singleton is shared across all plugin host processes, meaning there shouldn't be a risk for a race condition to corrupt the file being written on disk. Note that there is still a race condition risk when multiple Theia backends are running on the same host, but odds should be low.
1 parent a75dd66 commit c8fb5ad

File tree

1 file changed

+3
-6
lines changed

1 file changed

+3
-6
lines changed

packages/plugin-ext/src/main/node/plugins-key-value-storage.ts

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@
1414
// SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-only WITH Classpath-exception-2.0
1515
// *****************************************************************************
1616

17-
import { deepmerge } from '@theia/core/shared/@theia/application-package';
1817
import { injectable, inject, postConstruct } from '@theia/core/shared/inversify';
1918
import { FileSystemLocking } from '@theia/core/lib/node';
2019
import * as fs from '@theia/core/shared/fs-extra';
@@ -111,11 +110,9 @@ export class PluginsKeyValueStorage {
111110

112111
private syncStores(): void {
113112
this.syncStoresTimeout = setTimeout(async () => {
114-
await Promise.all(Array.from(this.storesToSync, async store => {
115-
await this.fsLocking.lockPath(store.fsPath, async storePath => {
116-
const valuesOnDisk = await this.readFromFile(storePath);
117-
store.values = deepmerge(valuesOnDisk, store.values);
118-
await this.writeToFile(storePath, store.values);
113+
await Promise.all(Array.from(this.storesToSync, async ({ fsPath, values }) => {
114+
await this.fsLocking.lockPath(fsPath, async storePath => {
115+
await this.writeToFile(storePath, values);
119116
});
120117
}));
121118
this.storesToSync.clear();

0 commit comments

Comments
 (0)