microsoft / mindaro

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

An item with the same key has already been added. Key: my-namespace-mongodb #171

Open V4A001 opened 3 years ago

V4A001 commented 3 years ago

Describe the bug I try to debug my application in kubernetes. However, upon connecting I get this error about mongodb adding duplicate keys. No idea why this is happening as I have the mongodb running from another party. The debugger disconnects before reaching my code.

To Reproduce Connect to kubernetes.

**Expected behavior** Debug my application. **Logs** Attach logs from the following directory: 2021-05-05T18:12:36.0830742Z | MindaroCli | TRACE | Event: Command.Start {"properties":{"arguments":"connect --namespace my-namespace --service myapp-connector --context myapp-aks-002-acc --local-port 6000 --env c:\\users\\myuser\\appdata\\local\\temp\\tmpd5aa.tmp.env --script c:\\users\\myuser\\appdata\\local\\temp\\tmpd5ab.tmp --control-port 4607 --ppid 16948 --elevation-requests []","isRoutingEnabled":"false"},"metrics":null}\nOperation context: {"clientRequestId":null,"correlationId":"7b0436dd-3093-4662-bff5-90a307853dd5:7fe004f92b66","requestId":null,"userSubscriptionId":null,"startTime":"2021-05-05T18:12:35.5765493Z","userAgent":"LPK/2.1.20210411.1-5dda536c VisualStudio/16.9.31105.61","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210408.1","requestHeaders":{},"loggingProperties":{"applicationName":"MindaroCli","deviceOperatingSystem":"Microsoft Windows 10.0.19042","framework":".NET Core 3.1.14","macAddressHash":"2c3b847a61c31d1266a60a2a3628aa890b645f7fff0eb94eaa893b47bdeac62f","processId":28032,"targetEnvironment":"Production","commandId":"7fe004f92b66"}} 2021-05-05T18:12:36.3291641Z | MindaroCli | TRACE | Running Microsoft.BridgeToKubernetes.Exe.Commands.Connect.ConnectCommand...\nOperation context: {"clientRequestId":null,"correlationId":"7b0436dd-3093-4662-bff5-90a307853dd5:7fe004f92b66","requestId":null,"userSubscriptionId":null,"startTime":"2021-05-05T18:12:35.5765493Z","userAgent":"LPK/2.1.20210411.1-5dda536c VisualStudio/16.9.31105.61","requestHttpMethod":null,"requestUri":null,"version":"1.0.20210408.1","requestHeaders":{},"loggingProperties":{"applicationName":"MindaroCli","deviceOperatingSystem":"Microsoft Windows 10.0.19042","framework":".NET Core 3.1.14","macAddressHash":"2c3b847a61c31d1266a60a2a3628aa890b645f7fff0eb94eaa893b47bdeac62f","processId":28032,"targetEnvironment":"Production","commandId":"7fe004f92b66","targetNamespaceName":"my-namespace","targetKubeConfigContextName":"myapp-aks-002-acc","targetServiceName":"myapp-connector","isRoutingEnabled":false}} 2021-05-05T18:12:36.3485814Z | MindaroCli | TRACE | Initializing progress reporter... 2021-05-05T18:12:40.0714310Z | MindaroCli | TRACE | Remoting started listening on 4607 2021-05-05T18:12:50.9378227Z | MindaroCli | TRACE | Waiting for 'myapp-connector-7477bd68cb-kddwk' in namespace 'my-namespace' to reach running state...\n 2021-05-05T18:12:51.0681276Z | MindaroCli | TRACE | Deployment 'my-namespace/myapp-connector' patched to run agent.\n 2021-05-05T18:12:51.0749897Z | MindaroCli | TRACE | Found container 'connectorapi' in pod 'myapp-connector-7477bd68cb-kddwk'.\n 2021-05-05T18:12:51.0947675Z | MindaroCli | TRACE | Preparing to run Bridge To Kubernetes configured as pod my-namespace/myapp-connector-7477bd68cb-kddwk ...\n 2021-05-05T18:12:54.8602946Z | MindaroCli | TRACE | Connection established.\n 2021-05-05T18:12:57.9934342Z | MindaroCli | TRACE | Service 'myapp-connector' is available on 127.1.1.27:8080.\n 2021-05-05T18:12:57.9961371Z | MindaroCli | TRACE | Service 'my-namespace-connector' is available on 127.1.1.28:8080.\n 2021-05-05T18:12:57.9975408Z | MindaroCli | TRACE | Service 'my-namespace-connector' is available on 127.1.1.28:4567.\n 2021-05-05T18:12:57.9987094Z | MindaroCli | TRACE | Service 'my-namespace-connector' is available on 127.1.1.28:9999.\n 2021-05-05T18:12:57.9998947Z | MindaroCli | TRACE | Service 'my-namespace-connector-openapi-data-app' is available on 127.1.1.29:8080.\n 2021-05-05T18:12:58.0015468Z | MindaroCli | TRACE | Service 'my-namespace-mongodb' is available on 127.1.1.30:27017.\n 2021-05-05T18:12:58.0032345Z | MindaroCli | TRACE | Service 'my-namespace-mongodb' is available on 127.1.1.31:27017.\n 2021-05-05T18:12:58.1327338Z | MindaroCli | ERROR | Dependency: Service Run - Port Forward {"target":null,"success":false,"duration":null,"properties":{"requestId":"null","clientRequestId":"null","correlationRequestId":"null"}} 2021-05-05T18:12:58.1369773Z | MindaroCli | ERROR | ServiceConnectCommand.ExecuteInnerAsync caught exception System.ArgumentException: An item with the same key has already been added. Key: my-namespace-mongodb\n at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)\n at Microsoft.BridgeToKubernetes.Library.Connect.LocalEnvironmentManager.StartServiceRoutersInnerAsync(String devhostAgentClientTarget, ContainerWorkloadInfo workloadInfo, IEnumerable`1 elevationRequests, IProgress`1 progress, CancellationToken cancellationToken)\n at Microsoft.BridgeToKubernetes.Library.Connect.LocalEnvironmentManager.StartServiceRoutersAsync(String devhostAgentClientTarget, ContainerWorkloadInfo workloadInfo, IEnumerable`1 elevationRequests, IProgress`1 progress, CancellationToken cancellationToken)\n at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.<>c__DisplayClass16_0.<b__0>d.MoveNext()\n--- End of stack trace from previous location where exception was thrown ---\n at Microsoft.BridgeToKubernetes.Library.ManagementClients.ManagementClientExceptionStrategy.RunWithHandlingAsync[T](Func`1 func, FailureConfig failureConfig)\n at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.ConfigureLocalHostAsync(ContainerWorkloadInfo containerWorkloadInfo, Int32[] localPorts, IEnumerable`1 elevationRequests, IProgress`1 progress, CancellationToken cancellationToken)\n at Microsoft.BridgeToKubernetes.Exe.Commands.Connect.ConnectCommand.ExecuteInnerAsync(IConnectManagementClient connectManagementClient, Action`1 workloadStartedHandler, CancellationToken cancellationToken, IRoutingManagementClient routingManagementClient) 2021-05-05T18:12:58.1382900Z | MindaroCli | ERROR | Connect operation failed.\n 2021-05-05T18:12:58.1397366Z | MindaroCli | TRACE | Stopping workload and cleaning up...\n 2021-05-05T18:12:58.3207967Z | MindaroCli | TRACE | Restore: Deployment 'myapp-connector' restored to original state with image 'myregistry.azurecr.io/myapp-connector:v2'.\n 2021-05-05T18:12:59.5997716Z | MindaroCli | ERROR | Dependency: Service Run - Port Forward {"target":null,"success":false,"duration":null,"properties":{"requestId":"null","clientRequestId":"null","correlationRequestId":"null"}} 2021-05-05T18:13:00.2589816Z | MindaroCli | ERROR | An unexpected error occurred: 'An item with the same key has already been added. Key: my-namespace-mongodb'\n 2021-05-05T18:13:00.2597886Z | MindaroCli | ERROR | To see our active issues or file a bug report, please visit https://aka.ms/bridge-to-k8s-report.\n 2021-05-05T18:13:00.2619023Z | MindaroCli | ERROR | For diagnostic information, see logs at 'C:\Users\myuser\AppData\Local\Temp\Bridge To Kubernetes'.\n 2021-05-05T18:13:00.2757513Z | MindaroCli | ERROR | Logging handled exception: System.ArgumentException: {"ClassName":"System.ArgumentException","Message":"An item with the same key has already been added. Key: my-namespace-mongodb","Data":null,"InnerException":null,"HelpURL":null,"StackTraceString":" at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)\r\n at Microsoft.BridgeToKubernetes.Library.Connect.LocalEnvironmentManager.StartServiceRoutersInnerAsync(String devhostAgentClientTarget, ContainerWorkloadInfo workloadInfo, IEnumerable`1 elevationRequests, IProgress`1 progress, CancellationToken cancellationToken)\r\n at Microsoft.BridgeToKubernetes.Library.Connect.LocalEnvironmentManager.StartServiceRoutersAsync(String devhostAgentClientTarget, ContainerWorkloadInfo workloadInfo, IEnumerable`1 elevationRequests, IProgress`1 progress, CancellationToken cancellationToken)\r\n at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.<>c__DisplayClass16_0.<b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.BridgeToKubernetes.Library.ManagementClients.ManagementClientExceptionStrategy.RunWithHandlingAsync[T](Func`1 func, FailureConfig failureConfig)\r\n at Microsoft.BridgeToKubernetes.Library.ManagementClients.ConnectManagementClient.ConfigureLocalHostAsync(ContainerWorkloadInfo containerWorkloadInfo, Int32[] localPorts, IEnumerable`1 elevationRequests, IProgress`1 progress, CancellationToken cancellationToken)\r\n at Microsoft.BridgeToKubernetes.Exe.Commands.Connect.ConnectCommand.ExecuteInnerAsync(IConnectManagementClient connectManagementClient, Action`1 workloadStartedHandler, CancellationToken cancellationToken, IRoutingManagementClient routingManagementClient)\r\n at Microsoft.BridgeToKubernetes.Exe.Commands.Connect.ConnectCommand.ExecuteInnerAsync(IConnectManagementClient connectManagementClient, Action`1 workloadStartedHandler, CancellationToken cancellationToken, IRoutingManagementClient routingManagementClient)\r\n at Microsoft.BridgeToKubernetes.Exe.Commands.Connect.ConnectCommand.ExecuteAsync()\r\n at Microsoft.BridgeToKubernetes.Exe.CliApp.RunCommandAsync(String[] args, CancellationToken cancellationToken)\r\n at Microsoft.BridgeToKubernetes.Exe.CliApp.ExecuteAsync(String[] args, CancellationToken cancellationToken)","RemoteStackTraceString":null,"RemoteStackIndex":0,"ExceptionMethod":null,"HResult":-2147024809,"Source":"System.Private.CoreLib","WatsonBuckets":null,"ParamName":null} 2021-05-05T18:13:00.2849426Z | MindaroCli | TRACE | Event: Command.End {"properties":{"arguments":"connect --namespace my-namespace --service myapp-connector --context myapp-aks-002-acc --local-port 6000 --env c:\\users\\myuser\\appdata\\local\\temp\\tmpd5aa.tmp.env --script c:\\users\\myuser\\appdata\\local\\temp\\tmpd5ab.tmp --control-port 4607 --ppid 16948 --elevation-requests []","result":"Failed","failureReason":"An item with the same key has already been added. Key: my-namespace-mongodb"},"metrics":{"duration":24368.0}} For Windows: %TEMP%/Bridge to Kubernetes For OSX/Linux: $TMPDIR/Bridge to Kubernetes If you are a Visual Studio user, - Set the environment variable MS_VS_AZUREDEVSPACES_TOOLS_LOGGING_ENABLED=true - Open Visual Studio and run your scenario - Provide logs from: %temp%\Microsoft.VisualStudio.Kubernetes.Debugging { "timestamp": "2021-05-05 20-13-02.065", "message": "Query the debug targets for debug launch of Connect service", "exception": { "type": "System.AggregateException", "message": "One or more errors occurred.", "stack": " at Microsoft.VisualStudio.Kubernetes.Debugging.ServiceHub.Connect.ConnectService.<>c__DisplayClass10_0.<b__0>d.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.VisualStudio.Kubernetes.Debugging.RpcContracts.Telemetry.KubeConnectScopeBase`1.d__27`1.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.VisualStudio.Kubernetes.Debugging.ServiceHub.Connect.ConnectService.d__10.MoveNext()", "code": -2146233088, "inner": { "type": "Microsoft.VisualStudio.Kubernetes.Debugging.RpcContracts.DscException", "message": "Connect operation failed.\r\nAn unexpected error occurred: 'An item with the same key has already been added. Key: scsn-acc-mongodb'\r\nTo see our active issues or file a bug report, please visit https://aka.ms/bridge-to-k8s-report.\r\nFor diagnostic information, see logs at 'C:\\Users\\JelleOssewaardeVOICE\\AppData\\Local\\Temp\\Bridge To Kubernetes'.\r\n", "stack": " at Microsoft.VisualStudio.Kubernetes.Debugging.ServiceHub.DscClient.d__16.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)\r\n at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)\r\n at Microsoft.VisualStudio.Kubernetes.Debugging.ServiceHub.DscClient.d__18.MoveNext()\r\n--- End of stack trace from previous location where exception was thrown ---\r\n at Microsoft.VisualStudio.Telemetry.WindowsErrorReporting.WatsonReport.GetClrWatsonExceptionInfo(Exception exceptionObject)", "code": -2146233088, "inner": null } }, "operationName": "AzureDevSpacesLocalDebugProfileLaunchTargetsProvider.QueryDebugTargetsForDebugLaunchAsync", "stage": "End", "elapsedTime": "00:00:36.8330690", "completionState": "Error" } **Environment Details** Client used (VS Code/Visual Studio): Client's version: Operating System: **Additional context** Add any other outputs from the clients or context you would like to share.
daniv-msft commented 3 years ago

Thanks @V4A001 for reporting this issue. This looks like the same issue as https://github.com/microsoft/mindaro/issues/155. Could you please confirm that you have some headless services running in your cluster?

We released the fix on VS Code but we need a bit more validation to release it in Visual Studio. Would using VS Code be a possible alternative for you in the meantime? Else, you might install a previous version of the Visual Studio extension to unblock you (cf. https://github.com/microsoft/mindaro/issues/155#issuecomment-825902824).