dapr / dotnet-sdk

Dapr SDK for .NET
Apache License 2.0
1.12k stars 340 forks source link

Use "localhost" instead of "127.0.0.1" for the sidecar host address #1032

Open cgillum opened 1 year ago

cgillum commented 1 year ago

Describe the proposal

Currently we use 127.0.0.1 when accessing the Dapr sidecar from the .NET SDK. This is hardcoded here. We should change this to instead be localhost because:

  1. 127.0.0.1 only works with IPv4 whereas localhost works with both IPv4 and IPv6.
  2. Unlike with localhost, using 127.0.0.1 can't resolve to local WSL2 endpoints from the Windows OS, which is a hindrance for local dev/test on Windows.

As an alternative, we could consider making the host address configurable via an environment variable.

ondmal commented 1 year ago

Hi @cgillum.

As an alternative, we could consider making the host address configurable via an environment variable.

cgillum commented 1 year ago

Thanks for the response @ondmal.

Do you have any proposal for the environment variable name?

Just throwing this out there, but how about DAPR_HOST?

Do you still want to use localhost if the environment variable is not defined?

Yes, the switch to localhost solves the immediate blockers that I'm running into more easily than an environment variable would.

ondmal commented 1 year ago

I do not know the system well, so I can´t say what is already reserved. But DAPR_HOST looks good to me.

EDIT: Looks like DAPR_HOST is good fit, since it is already used in the code base:

https://github.com/search?p=1&q=org%3Adapr+DAPR_HOST&type=Code

but it is missing here in docs: https://docs.dapr.io/reference/environment/