-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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(notebooks): fix race condition in view registration (#13106) #13115
fix(notebooks): fix race condition in view registration (#13106) #13115
Conversation
570a7ba
to
e0f6484
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This fix looks a bit overengineered to me. The only thing that is actually incorrect is the order in which we wait for things in waitForNotebookProvider
. We can fix the issue by just reordering what we're doing in there:
protected async waitForNotebookProvider(type: string): Promise<NotebookProviderInfo | undefined> {
if (this.notebookProviders.has(type)) {
return this.notebookProviders.get(type);
}
const deferred = new Deferred<NotebookProviderInfo | undefined>();
// 20 seconds of timeout
const timeoutDuration = 20_000;
const disposable = this.onDidRegisterNotebookSerializer(viewType => {
if (viewType === type) {
clearTimeout(timeout);
disposable.dispose();
deferred.resolve(this.notebookProviders.get(type));
}
});
const timeout = setTimeout(() => {
clearTimeout(timeout);
disposable.dispose();
deferred.reject(new Error(`Timed out while waiting for notebook serializer for type ${type} to be registered`));
}, timeoutDuration);
await Promise.all(this.willUseNotebookSerializerEmitter.fire(type));
return deferred.promise;
}
The main issue seems to be that the provider is registered during the await Promise.all(this.willUseNotebookSerializerEmitter.fire(type));
call. We basically have a blind spot there. If we register the callback before that, we don't need the replay mechanism.
@msujew I can give that a try. Though those closure captures still need to be fixed. |
…a#13106) Fixes a race condition that occurred when event handlers for `onDidRegisterNotebookSerializer` were registered *after* said event was fired. Signed-off-by: Beniamino Ventura <benia@protonmail.com>
e0f6484
to
f7b06e4
Compare
@msujew You were right, that approach also works and it's a lot cleaner. Thank you. I force-pushed a new commit. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Alright, looks good to me 👍
What it does
Fixes #13106
Fixes a race condition that occurred when event handlers for
onDidRegisterNotebookSerializer
were registered after said event was fired. This prevented the correct rendering of a notebook the first time one was opened during the lifetime of a page.To solve this, we're storing the events that are fired before any event handler is registered and replay them for the first such handler only.Review comments highlighted this was not necessary and that there was a simpler solutionHow to test
Install the necessary vscode plugins:
ms-python.python
(https://open-vsx.org/extension/ms-python/python)ms-toolsai.jupyter
(https://open-vsx.org/extension/ms-toolsai/jupyter)Create a new file with extension
.ipynb
Open the file from the explorer
Observe the notebook UI is shown immediately, as opposed to an empty editor before the patch.
Follow-ups
Review checklist
Reminder for reviewers