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(notebooks): fix race condition in view registration (#13106) #13115

Merged

Conversation

bvenreply
Copy link
Contributor

@bvenreply bvenreply commented Nov 28, 2023

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 solution

How to test

Follow-ups

Review checklist

Reminder for reviewers

@JonasHelming JonasHelming requested a review from msujew November 29, 2023 07:54
@bvenreply bvenreply force-pushed the fix_on_did_register_notebook_serializer branch from 570a7ba to e0f6484 Compare November 29, 2023 18:44
Copy link
Member

@msujew msujew left a 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.

@bvenreply
Copy link
Contributor Author

bvenreply commented Nov 29, 2023

@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>
@bvenreply bvenreply force-pushed the fix_on_did_register_notebook_serializer branch from e0f6484 to f7b06e4 Compare November 29, 2023 21:01
@bvenreply
Copy link
Contributor Author

@msujew You were right, that approach also works and it's a lot cleaner. Thank you. I force-pushed a new commit.

@bvenreply bvenreply requested a review from msujew November 29, 2023 21:02
Copy link
Member

@msujew msujew left a 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 👍

@msujew msujew merged commit 1943c80 into eclipse-theia:master Nov 29, 2023
14 checks passed
@vince-fugnitto vince-fugnitto added this to the 1.44.0 milestone Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

Successfully merging this pull request may close these issues.

Notebooks are not rendered correctly when opened for the first time in a page load
3 participants