Skip to content

Fix removing tunnels when the tunnel factory throws an error#186566

Merged
alexr00 merged 3 commits intomicrosoft:mainfrom
joshaber:patch-1
Jun 29, 2023
Merged

Fix removing tunnels when the tunnel factory throws an error#186566
alexr00 merged 3 commits intomicrosoft:mainfrom
joshaber:patch-1

Conversation

@joshaber
Copy link
Contributor

@joshaber joshaber commented Jun 28, 2023

If the tunnel factory in the web throws an error, VS Code will catch that error but maintain a port mapping for that port, which means if you try to forward the same port again, it won't re-call the tunnel factory since it thinks it's already forwarding the port.

Steps to reproduce

  1. The tunnel gets added to the tunnel service's map:
    this.addTunnelToMap(remoteHost, remotePort, tunnel);
  2. It will catch the error and return undefined: https://github.com/microsoft/vscode/blob/e7ee47c5ec2046533cb9017d7c403b32e2bfebd2/src/vs/workbench/contrib/remote/browser/tunnelFactory.ts#L65C1-L68
  3. If the tunnel promise ends up resolving to an empty value, it will try to remove the empty mapping:
    this.removeEmptyTunnelFromMap(remoteHost!, remotePort);
  4. But as part of that it again tries to resolve the promise, but instead of await'ing the tunnel promise it awaits the object from the tunnel map that contains the promise:
    const tunnelResult = await tunnel;
  5. So it doesn't actually remove the port mapping since the result isn't undefined:
    if (!tunnelResult) {

cc @alexr00

@alexr00 alexr00 self-assigned this Jun 29, 2023
@alexr00 alexr00 added this to the June 2023 milestone Jun 29, 2023
alexr00
alexr00 previously approved these changes Jun 29, 2023
Copy link
Member

@alexr00 alexr00 left a comment

Choose a reason for hiding this comment

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

@joshaber, this is great. Thank you for debugging into this and for the details of your investigation!

@alexr00 alexr00 enabled auto-merge (squash) June 29, 2023 09:38
@alexr00 alexr00 merged commit 661fbc9 into microsoft:main Jun 29, 2023
@joshaber joshaber deleted the patch-1 branch June 29, 2023 20:54
@github-actions github-actions bot locked and limited conversation to collaborators Aug 13, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants