microsoft / mindaro

Bridge to Kubernetes - for Visual Studio and Visual Studio Code
MIT License
307 stars 106 forks source link

Setting useKubernetesServiceEnvironmentVariables to true causes crash #236

Open indiejames opened 2 years ago

indiejames commented 2 years ago

Describe the bug When I set useKubernetesServiceEnvironmentVariables to 'true' (defaults to 'false') in the bridge-to-kubernetes.resource definition in tasks.json and launch the debugger the startup crashes with the following error:

Failed to establish a connection. Error: Port 55049 is already in use on your machine. Please free this port and try again. Use 'netstat -ano' command to find which program is using this port.

To Reproduce After configuring for local tunneling, edit the bridge-to-kubernetes.resource task in tasks.json and set the useKubernetesServiceEnvironmentVariables entry to 'true'. Start a debug session and watch the terminal output to see the crash, followed by a popup asking if you want to abort.

**Expected behavior** The service should launch locally and run with environment variables set based on those defined in the Kubernetes cluster. **Logs** 2021-09-30T21:55:53.6974830Z | MindaroCli | TRACE | Event: Command.Start {"properties":{"arguments":"connect --service harmony-service-example --env /var/folders/_6/zt0qbjxd17s4qww0_yvyd_6hh1tml0/t/tmp-33222vinl08njw5l5.env --script /var/folders/_6/zt0qbjxd17s4qww0_yvyd_6hh1tml0/t/tmp-33222vinl08njw5l5.env.cmd --control-port 56952 --ppid 33220 --namespace argo --use-kubernetes-service-environment-variables --local-port 5000","isRoutingEnabled":"false"},"metrics":null}\nOperation context: {"clientRequestId":null,"correlationId":"916f3eab-c305-4084-b51d-f1aca7aabe071633038193418:f873b9ff7bae","requestId":null,"userSubscriptionId":null,"startTime":"2021-09-30T21:55:53.3827450Z","userAgent":"VSCode/1.0.120210803","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210723.6","requestHeaders":{},"loggingProperties":{"applicationName":"MindaroCli","deviceOperatingSystem":"Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Aug 24 20:28:00 PDT 2021; root:xnu-6153.141.40~1/RELEASE_X86_64","framework":".NET Core 3.1.9","macAddressHash":"dfbe6f9a64e3bb8239cbbb6ade76cf8e2ed251f1e181db90169abb316e750214","processId":34559,"targetEnvironment":"Production","commandId":"f873b9ff7bae"}} 2021-09-30T21:55:53.7753520Z | MindaroCli | TRACE | Running Microsoft.BridgeToKubernetes.Exe.Commands.Connect.ConnectCommand...\nOperation context: {"clientRequestId":null,"correlationId":"916f3eab-c305-4084-b51d-f1aca7aabe071633038193418:f873b9ff7bae","requestId":null,"userSubscriptionId":null,"startTime":"2021-09-30T21:55:53.3827450Z","userAgent":"VSCode/1.0.120210803","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210723.6","requestHeaders":{},"loggingProperties":{"applicationName":"MindaroCli","deviceOperatingSystem":"Darwin 19.6.0 Darwin Kernel Version 19.6.0: Tue Aug 24 20:28:00 PDT 2021; root:xnu-6153.141.40~1/RELEASE_X86_64","framework":".NET Core 3.1.9","macAddressHash":"dfbe6f9a64e3bb8239cbbb6ade76cf8e2ed251f1e181db90169abb316e750214","processId":34559,"targetEnvironment":"Production","commandId":"f873b9ff7bae","targetServiceName":"harmony-service-example","isRoutingEnabled":false}} 2021-09-30T21:55:56.1677600Z | MindaroCli | TRACE | Remoting started listening on 56952 2021-09-30T21:56:02.3334980Z | MindaroCli | TRACE | Connection established.\n 2021-09-30T21:56:02.5152590Z | MindaroCli | WARNG | Port 55049 is already in use on your machine. Please free this port and try again. Use 'netstat -ano' command to find which program is using this port. 2021-09-30T21:56:02.5155230Z | MindaroCli | ERROR | Port 55049 is already in use on your machine. Please free this port and try again. Use 'netstat -ano' command to find which program is using this port.\n 2021-09-30T21:56:02.5159700Z | MindaroCli | TRACE | Stopping workload and cleaning up...\n 2021-09-30T21:56:03.7285030Z | MindaroCli | TRACE | Event: Command.End {"properties":{"arguments":"connect --service harmony-service-example --env /var/folders/_6/zt0qbjxd17s4qww0_yvyd_6hh1tml0/t/tmp-33222vinl08njw5l5.env --script /var/folders/_6/zt0qbjxd17s4qww0_yvyd_6hh1tml0/t/tmp-33222vinl08njw5l5.env.cmd --control-port 56952 --ppid 33220 --namespace argo --use-kubernetes-service-environment-variables --local-port 5000","result":"Failed","failureReason":"Port 55049 is already in use on your machine. Please free this port and try again. Use 'netstat -ano' command to find which program is using this port."},"metrics":{"duration":10092.0}} **Environment Details** Client used (VS Code): mindaro.mindaro@1.0.120210803 Client's version: Operating System: macOS Catalina **Additional context** The service launches and runs if I set useKubernetesServiceEnvironmentVariables to 'false', but of course the environment variables are not set in that case.
amsoedal commented 2 years ago

Hi @indiejames, thanks for reporting this issue. I'm taking a look and will try to respond on Monday.

amsoedal commented 2 years ago

@indiejames I was able to reproduce the issue, and I believe we have a regression in this code path. Will discuss with my colleagues today and hopefully get back to you with either a workaround or an updated timeline. In the meantime, is using Bridge w/o service environment variables a blocker for you? You might be able to declare the environment variables this way: https://docs.microsoft.com/en-us/visualstudio/bridge/configure-bridge-to-kubernetes#create-an-environment-variable-with-a-constant-value

indiejames commented 2 years ago

No, this is not a blocker - I can set the environment variables manually.

saumil-d commented 2 years ago

Hi, I believe I'm running into the exact same issue. Are there any updates on this? Thanks

amsoedal commented 2 years ago

Hi @saumil-d, we haven't had time to prioritize this issue yet unfortunately, but would you be able to follow the workaround mentioned above?

shangzhipan commented 2 years ago

Hi @amsoedal, this issue is still persisting. It seems to be only happening on Mac devices. Do you have any updates on this?

aldycool commented 2 years ago

I also use Mac with the same issue.