Dapr.Extensions.Configuration.AddDaprSecretStore() fails if the sidecar and app are started separately
- Dominant language
- C#
- Stars
- 1.2k
- Forks
- 378
- Avg merge
- 1d 22h
- Merged PRs (30d)
- 5
Description
## Expected Behavior
When starting the application after Dapr sidecar, `AddDaprSecretStore()` should not time out and throw exceptions:
```C#
using Dapr.Client;
using Dapr.Extensions.Configuration;
var builder = WebApplication.CreateBuilder(args);
using var client = new DaprClientBuilder().Build();
builder.Configuration.AddDaprSecretStore("secrets", client, TimeSpan.FromSeconds(5));
var app = builder.Build();
app.Run();
```
## Actual Behavior
When running the sidecar and the app separately, exception is thrown:
```shell
# Run in separate terminal
$ dapr run --app-id "app" --app-port "5200"
```
and then the app:
```shell
$ dotnet run
Building...
Unhandled exception. System.Threading.Tasks.TaskCanceledException: A task was canceled.
at Dapr.Client.DaprClientGrpc.WaitForSidecarAsync(CancellationToken cancellationToken)
at Dapr.Extensions.Configuration.DaprSecretStore.DaprSecretStoreConfigurationProvider.LoadAsync()
at Dapr.Extensions.Configuration.DaprSecretStore.DaprSecretStoreConfigurationProvider.Load()
at Microsoft.Extensions.Configuration.ConfigurationManager.AddSource(IConfigurationSource source)
at Microsoft.Extensions.Configuration.ConfigurationManager.Microsoft.Extensions.Configuration.IConfigurationBuilder.Add(IConfigurationSource source)
at Dapr.Extensions.Configuration.DaprSecretStoreConfigurationExtensions.AddDaprSecretStore(IConfigurationBuilder configurationBuilder, String store, DaprClient client, TimeSpan sidecarWaitTimeout, IReadOnlyDictionary`2 metadata)
at Program.$(String[] args) in C:\src\dapr-bug-001\src\app\Program.cs:line 7
```
## Steps to Reproduce the Problem
I created a [Github repo](https://github.com/juris-greitans/dapr-sdk-add-dapr-secret-store-bug-001) containing minimal .NET 7 project to repeat the issue. The [README.md](https://github.com/juris-greitans/dapr-sdk-add-dapr-secret-store-bug-001/blob/main/README.md) contains more details.
In short:
1. Run the sidecar, but do not specify the application, e.g. `dapr run --app-id "app" --app-port "5200" --components-path "components"`
2. Run the application after sidecar has started, e.g. `dotnet run`
It seems to me that this behavior was first described in #779 - the sidecar is waiting when the app will start listening on its port, but the app is waiting for sidecar's `healthz/outbound` endpoint to return 2xx statuscode during startup.
Also #983 could be related.
## Release Note
RELEASE NOTE:
Contributor guide
Assessment
This issue has not been assessed yet.