Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent chrome storage resolving before entries are set #126

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from

Conversation

sameerank
Copy link
Contributor

@sameerank sameerank commented Dec 13, 2024


labels: mergeable

Fixes: #issue

Motivation and Context

We had a hypothesis in a debugging session that await this.storage.set may be resolving when the writing process starts, instead of when it finishes writing the fetched flags to storage and that this may be an idiosyncratic behavior of the Chrome storage implementation. If true, this could result in inconsistent, null assignments on application start if get assignment is called immediately after await init

Description

This is a draft of using an isInProcessOfInitializing method to wait before deciding if the store is usable

How has this been tested?

chrome.storage.onChanged.removeListener(listener);
applicationLogger.warn('Chrome storage write timeout for key:', key);
resolve();
}, 1000);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

One second is probably too long, but we also never expect to end up in this situation of needing the timeout. It's a precaution

(mockStorage.set as jest.Mock).mockResolvedValue(undefined);

// Start the set operation
const setPromise = storageMap.set(key, value);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This isn't exactly what I am hoping to test since the set operation isn't in progress, and I'm interested in testing that an entry hasn't been written yet between the time that the operation started and onChange was fired. I couldn't figure out how to write such a test.

@sameerank sameerank closed this Dec 14, 2024
@sameerank sameerank reopened this Dec 14, 2024
@sameerank sameerank marked this pull request as draft December 14, 2024 01:02

public constructor(private storageEngine: IStringStorageEngine, private cooldownSeconds = 0) {}

public isInitialized(): boolean {
return this.initialized;
}

public isInProcessOfInitializing(): boolean {
Copy link
Contributor Author

Choose a reason for hiding this comment

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

TODO add isInProcessOfInitializing to the IAsyncStore interface

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant