dapr / dapr/dotnet-sdk

Dapr service invocation throws SocketException when app is run separate from 'dapr run' CLI command

Open
#675 2 comments 1 reaction 0 assignees View on GitHub
question
Dominant language
C#
Stars
1.2k
Forks
378
Avg merge
1d 22h
Merged PRs (30d)
5

Description

Hi,

I'm fairly new to Dapr so I'm not sure if I'm doing something wrong or that what I'm trying to achieve is actually a supported scenario. However reading the [docs](https://docs.dapr.io/reference/cli/dapr-run/#run-sidecar-only) seems to indicate that this should be possible.

## Expected/Actual Behavior

If I run my app using the following ps1 file:

```powershell
$env:DAPR_APP_PORT = 5002
$env:DAPR_APP_ID = "MyApp"

dapr run --app-id $env:DAPR_APP_ID --app-port $env:DAPR_APP_PORT --app-protocol grpc -- dotnet run --no-build --framework netcoreapp3.1
```

I am able to call another service using `DaprClient.InvokeMethodGrpcAsync()`.

However, when I structure the ps1 file like this:

```powershell
$env:DAPR_APP_PORT = 5002
$env:DAPR_APP_ID = "MyApp"

dotnet run --no-build --framework netcoreapp3.1

dapr run --app-id $env:DAPR_APP_ID --app-port $env:DAPR_APP_PORT --app-protocol grpc
```

I get the following exception when executing the same code as in the first scenario:

```
System.Net.Sockets.SocketException
HResult=0x80004005
Message=No connection could be made because the target machine actively refused it.
Source=System.Private.CoreLib
StackTrace:
at System.Runtime.ExceptionServices.ExceptionDispatchInfo.Throw()
```

The Dapr console log doesn't seem to indicate any issue, other then a warning that no application command is found (which is correct since we run the application separately):

```
info: Microsoft.Hosting.Lifetime[0]
Now listening on: http://0.0.0.0:5002
info: Microsoft.Hosting.Lifetime[0]
Application started. Press Ctrl+C to shut down.
info: Microsoft.Hosting.Lifetime[0]
Hosting environment: Production
info: Microsoft.Hosting.Lifetime[0]
Content root path:
←[37;1mWARNING: no application command found.←[0m
Starting Dapr with id MyApp. HTTP Port: 51524. gRPC Port: 51525
time="2021-05-11T12:56:16.7641704+02:00" level=info msg="starting Dapr Runtime -- version 1.1.2 -- commit 3148f36" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7680055+02:00" level=info msg="log level set to: info" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7682984+02:00" level=info msg="metrics server started on :51526/" app_id="MyApp" instance= scope=dapr.metrics type=log ver=1.1.2
time="2021-05-11T12:56:16.7714937+02:00" level=info msg="standalone mode configured" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7715984+02:00" level=info msg="app id: MyApp" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.77164+02:00" level=info msg="mTLS is disabled. Skipping certificate request and tls validation" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7756055+02:00" level=info msg="local service entry announced: MyApp -> 10.232.4.10:51535" app_id="MyApp" instance= scope=dapr.contrib type=log ver=1.1.2
time="2021-05-11T12:56:16.7756055+02:00" level=info msg="Initialized name resolution to standalone" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7756055+02:00" level=info msg="waiting for all outstanding components to be processed" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7761934+02:00" level=info msg="all outstanding components processed" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.776523+02:00" level=info msg="enabled gRPC tracing middleware" app_id="MyApp" instance= scope=dapr.runtime.grpc.api type=log ver=1.1.2
time="2021-05-11T12:56:16.776523+02:00" level=info msg="enabled gRPC metrics middleware" app_id="MyApp" instance= scope=dapr.runtime.grpc.api type=log ver=1.1.2
time="2021-05-11T12:56:16.776523+02:00" level=info msg="API gRPC server is running on port 51525" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7770999+02:00" level=info msg="enabled metrics http middleware" app_id="MyApp" instance= scope=dapr.runtime.http type=log ver=1.1.2
time="2021-05-11T12:56:16.7770999+02:00" level=info msg="enabled tracing http middleware" app_id="MyApp" instance= scope=dapr.runtime.http type=log ver=1.1.2
time="2021-05-11T12:56:16.7770999+02:00" level=info msg="http server is running on port 51524" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7770999+02:00" level=info msg="The request body size parameter is: 4" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7776202+02:00" level=info msg="enabled gRPC tracing middleware" app_id="MyApp" instance= scope=dapr.runtime.grpc.internal type=log ver=1.1.2
time="2021-05-11T12:56:16.7776787+02:00" level=info msg="enabled gRPC metrics middleware" app_id="MyApp" instance= scope=dapr.runtime.grpc.internal type=log ver=1.1.2
time="2021-05-11T12:56:16.7782392+02:00" level=info msg="internal gRPC server is running on port 51535" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:16.7788158+02:00" level=info msg="application protocol: grpc. waiting on port 5002. This will block until the app is listening on that port." app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
You're up and running! Dapr logs will appear here.

time="2021-05-11T12:56:17.0911512+02:00" level=info msg="application discovered on port 5002" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
time="2021-05-11T12:56:17.091769+02:00" level=info msg="actor runtime started. actor idle timeout: 1h0m0s. actor scan interval: 30s" app_id="MyApp" instance= scope=dapr.runtime.actor type=log ver=1.1.2
time="2021-05-11T12:56:17.0931772+02:00" level=info msg="dapr initialized. Status: Running. Init Elapsed 322.2055ms" app_id="MyApp" instance= scope=dapr.runtime type=log ver=1.1.2
```

## Steps to Reproduce the Problem

1. Create an application that uses service invocation to call another application
2. Run the application as shown earlier

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.