microsoft / vscode

Visual Studio Code
https://code.visualstudio.com
MIT License
162.38k stars 28.62k forks source link

Connecting to Live Share session causes NPE in workspace trust subsystem #200682

Open leifwalsh opened 9 months ago

leifwalsh commented 9 months ago

Does this issue occur when all extensions are disabled?: Yes (all except Live Share)

Steps to Reproduce:

  1. Live Share: Sign In
  2. Try to connect to a Live Share session (click Join, sign in, then paste the invitation link)
  3. Window reloads, starts opening the live share workspace, presents a workspace trust modal, asking me to trust /tmp/vsliveshare-workspace-tmp-<stuff>/Visual Studio Live Share (Workspace). Click "Yes, I trust the authors". VS Code logs an exception and stops opening the workspace. <-- this is where the bug is, I'd expect it to open the workspace and connect
  4. Use Developer: Reload Window
  5. After reloading, we start in Restricted Mode, with a banner across the top "Restricted Mode is intended for safe code browsing...". Click Manage, then Trust. This time, no exception.
  6. Reload one more time, and now we're able to connect.

Here is the exception:

ERR Cannot read properties of undefined (reading 'scheme'): TypeError: Cannot read properties of undefined (reading 'scheme')
    at h.P (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:167197)
    at .../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:171789
    at Array.map (<anonymous>)
    at h.setUrisTrust (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:171777)
    at h.setWorkspaceTrust (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:171570)
    at m.completeWorkspaceTrustRequest (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2605:173655)
    at Object.run (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:2690:68778)
    at c.f (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:633:42862)
    at c.prompt (.../stable-af28b32d7e553898b2a91af498b1fb666fdebe0c/static/out/vs/workbench/workbench.web.main.js:766:23881)

It looks like one of the uris here is undefined:

https://github.com/microsoft/vscode/blob/af28b32d7e553898b2a91af498b1fb666fdebe0c/src/vs/workbench/services/workspaces/common/workspaceTrust.ts#L620

Maybe this runs too early or something, before the folders in the workspace are fully initialized?

I feel like I've seen other cases where I need to try multiple times to trust a workspace if I click it too quickly, but this is the most reproducible. All you need to do is, in the window where you're hosting the Live Share collaboration session, stop it and start a new one - this will get you a fresh (untrusted) workspace for the collaborator that's joining. This makes it pretty easy to test.

lszomoru commented 8 months ago

@sbatten, could you please take a look at this one as I know you have been looking at Live Share when we implemented workspace trust.