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

The grpc port is not being injected. #248

Open
DarqueWarrior opened this issue Aug 26, 2022 · 3 comments
Open

The grpc port is not being injected. #248

DarqueWarrior opened this issue Aug 26, 2022 · 3 comments
Labels
P3 Lowest priority

Comments

@DarqueWarrior
Copy link

The extension just like the CLI needs to inject the environment variables for HTTP and GRPC ports. When I was debugging an app that used the Client SDK I was getting the following error when deubgging:

Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware[1]
      An unhandled exception has occurred while executing the request.
      Dapr.DaprException: State operation failed: the Dapr endpoint indicated a failure. See InnerException for details.
       ---> Grpc.Core.RpcException: Status(StatusCode="Internal", Detail="Error starting gRPC call. HttpRequestException: Connection refused (127.0.0.1:50001) SocketException: Connection refused", DebugException="System.Net.Http.HttpRequestException: Connection refused (127.0.0.1:50001)
       ---> System.Net.Sockets.SocketException (111): Connection refused
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.ThrowException(SocketError error, CancellationToken cancellationToken)
         at System.Net.Sockets.Socket.AwaitableSocketAsyncEventArgs.System.Threading.Tasks.Sources.IValueTaskSource.GetResult(Int16 token)
         at System.Net.Sockets.Socket.<ConnectAsync>g__WaitForConnectWithCancellation|277_0(AwaitableSocketAsyncEventArgs saea, ValueTask connectTask, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at System.Net.Http.HttpConnectionPool.ConnectToTcpHostAsync(String host, Int32 port, HttpRequestMessage initialRequest, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.ConnectAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.AddHttp2ConnectionAsync(HttpRequestMessage request)
         at System.Threading.Tasks.TaskCompletionSourceWithCancellation`1.WaitWithCancellationAsync(CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.GetHttp2ConnectionAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.HttpConnectionPool.SendWithVersionDetectionAndRetryAsync(HttpRequestMessage request, Boolean async, Boolean doRequestAuth, CancellationToken cancellationToken)
         at System.Net.Http.DiagnosticsHandler.SendAsyncCore(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at System.Net.Http.RedirectHandler.SendAsync(HttpRequestMessage request, Boolean async, CancellationToken cancellationToken)
         at Grpc.Net.Client.Internal.GrpcCall`2.RunCall(HttpRequestMessage request, Nullable`1 timeout)")
         at Dapr.Client.DaprClientGrpc.GetStateAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         --- End of inner exception stack trace ---
         at Dapr.Client.DaprClientGrpc.GetStateAsync[TValue](String storeName, String key, Nullable`1 consistencyMode, IReadOnlyDictionary`2 metadata, CancellationToken cancellationToken)
         at Program.<>c.<<<Main>$>b__0_0>d.MoveNext() in /workspaces/MyDaprDemos/PubSub/src/Program.cs:line 9
      --- End of stack trace from previous location ---
         at Microsoft.AspNetCore.Http.RequestDelegateFactory.<ExecuteTask>g__ExecuteAwaited|58_0[T](Task`1 task, HttpContext httpContext)
         at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
         at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware: Error: An unhandled exception has occurred while executing the request.

The only way around it was to explicitly set the GRPC port in the tasks.json.

        {
            "grpcPort": 50001,
            "appId": "app1",
            "appPort": 5013,
            "httpPort": 3500,
            "label": "dapr-debug",
            "componentsPath": "./components/local",
            "type": "dapr",
            "dependsOn": "build"
        },

Even though my app did not use GRPC (directly) without that first line above the code would not work. When I changed my code to just use C# HttpClient everything worked. It only failed when using the SDK.

When I ran my app from the CLI (without the debugger) everything worked as expected.

@dbreshears dbreshears added this to the Future milestone Sep 14, 2022
@dbreshears dbreshears added the P3 Lowest priority label Sep 14, 2022
@dbreshears
Copy link
Member

Thanks for the feedback. This makes sense. Will add it to address in our future backlog

@jedjohan
Copy link

jedjohan commented Dec 3, 2022

Ohh, I've been stuck on this way too long. Thanks !!!!

@philliphoff
Copy link
Member

The Dapr Client SDK uses gRPC (by default) to communicate with the Dapr sidecar, so it makes sense you only see the issue then. Dapr used to use 50001 as the default gRPC port, but at some point switched to using a random port. The Dapr Client SDK still falls back to 50001 if not explicitly set in code or passed to the application via DAPR_GRPC_PORT environment variable. That's why it works when you tell explicitly tell Dapr to use that (former default) port. That is, the Dapr extension is not injecting any environment variables into the application being run/debugged.

Ideally we don't want any Dapr ports statically defined in configuration files as that's prone to colliding with something else, as well as just being a maintenance nightmare. The problem is that the VS Code debugging API makes it difficult to flow information from a task (in tasks.json) to a launch configuration (in launch.json). That is, there's no opportunity to take the dynamically chosen port from the dapr run command and pass it along to the debug launch configuration for injection as an environment variable. At least, that was the case at the time--some investigation is needed to determine if that's still the case, though I've not heard of any related changes. (It's a common theme across extensions that coordinate launch and debugging, like Docker tools.)

@philliphoff philliphoff removed this from the Future milestone Feb 4, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
P3 Lowest priority
Projects
None yet
Development

No branches or pull requests

4 participants