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

Allow reloading changes in workspace extensions #208698

Closed
connor4312 opened this issue Mar 25, 2024 · 4 comments
Closed

Allow reloading changes in workspace extensions #208698

connor4312 opened this issue Mar 25, 2024 · 4 comments
Assignees
Labels

Comments

@connor4312
Copy link
Member

Testing #208184

It's my impression (which may not be correct) that extensions which export a deactivate function signal they can be gracefully deactivated in a running extension host. The selfhost test provider is one of these. It would be pretty nice if the extension was automatically deactivated and reloaded with the new code when it changes within a workspace.

@sandy081
Copy link
Member

sandy081 commented Apr 9, 2024

@alexdima I believe it is not possible to unload and load a new version of extension even if the extension can be safely deactivated. Am I right?

@alexdima
Copy link
Member

I believe it is not possible to unload and load a new version of extension even if the extension can be safely deactivated.

The problem is that we cannot guarantee an extension is deactivated safely because we can't detach it from all possible event emitters and then safely unload the code. So for example if an extension forgets a single subscription behind this could cause buggy behavior. We could invest in tracking all subscriptions created by an extension and disposing them ourselves, but there might remain other places like sockets, intervals, timeouts which we might miss.

@connor4312
Copy link
Member Author

connor4312 commented Jun 13, 2024

The problem is that we cannot guarantee an extension is deactivated safely because we can't detach it from all possible event emitters and then safely unload the code.

Isn't that the point of ExtensionContext.subscriptions and/or the deactivate function? It would be a bug in the extension if that doesn't catch everything.

@alexdima
Copy link
Member

alexdima commented Jun 13, 2024

It would be a bug in the extension if that doesn't catch everything.

Yes, you're right! But my point is that we, as a platform, cannot guarantee safe unloading of all extensions.

I agree that someone can write a good quality extension which keeps track of its disposables properly, but my argument is that someone might also write an extension where some disposables are not kept track of, which would lead to undefined behavior or unreproducible bugs. Other failure modes include: an extension patching the global Error.stack and forgetting to unpatch it (like some sourcemap support node modules), an extension using setInterval, an extension registering to a document change event, an extension loading a native node module which probably can't ever be unloaded etc. etc. All these leaks would make it that we hold on to the old code, to the old objects which might throw in unexpected ways. I also don't know if adding support for this would block ESM adoption, I'm not sure if someone can simply "reload" ESM modules. All in all, the bugs that would come out of this might not be worth it and a "Restart Extension Host" is so fast anyways. (takes a couple seconds)

... so maybe you'd also be happy with automatic Extension Host restarting?

@vs-code-engineering vs-code-engineering bot locked and limited conversation to collaborators Jul 28, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

3 participants