Navigation Menu

Skip to content
This repository has been archived by the owner on Jan 22, 2019. It is now read-only.

fix: a race condition causing settings to be overwritten #92

Merged
merged 1 commit into from Aug 24, 2018

Conversation

chrismwendt
Copy link

@chrismwendt chrismwendt commented Aug 24, 2018

jsonc-parser's setProperty() takes an object, path, and value, and sets the value at the path in the object. Along the way, setProperty() mutates the path by Array.pop()ping off each component until the path is empty. In browser-extensions, setProperty() is called multiple times with the same path because a combineLatest reuses the latest viewerConfiguredExtensions when the adjacent configurationCascade emits. That was not a problem unless the user clicked the toggle button again before viewerConfiguredExtensions emitted, which would create a new path. There was a window of time during which clicking the toggle button would apply the settings change with the old (mutated and empty) path. That would set the top level value of client settings to whatever the value of the toggle was (true or false).

Now, the mutation happens on a copy of the array, so the original path is left intact.

This is a workaround until a fix is merged upstream: microsoft/node-jsonc-parser#12

Resolves sourcegraph/sourcegraph#12972

cc @KattMingMing no need to work on that issue now

@chrismwendt chrismwendt merged commit 3c81e9d into master Aug 24, 2018
@chrismwendt chrismwendt deleted the fix-settings-being-overwritten-to-true branch August 24, 2018 09:20
setProperty(clientSettings, args.edit.path, args.edit.value, format)
// TODO(chris): remove `.slice()` (which guards against
// mutation) once
// https://github.com/Microsoft/node-jsonc-parser/pull/12

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we are using a fork by @sqs?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's nothing new in the fork microsoft/node-jsonc-parser@master...sqs:master

@sourcegraph-bot
Copy link

🎉 This PR is included in version 1.11.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

KattMingMing pushed a commit that referenced this pull request Aug 24, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants