-
Notifications
You must be signed in to change notification settings - Fork 45
Open
Description
Recently I faced an odd behavior for OpenFeature.Api class while calling SetProviderAsync(provider, token);
While executing following piece of code:
using Microsoft.Extensions.Logging;
using OpenFeature;
using OpenFeature.Constant;
using OpenFeature.Contrib.Providers.Flagd;
var syncEndpointUri = new Uri("http://127.0.0.1:40009");
var loggerFactory = LoggerFactory.Create(builder =>
{
builder.AddFilter("Microsoft", LogLevel.Warning)
.AddFilter("System", LogLevel.Warning)
.AddSimpleConsole(options =>
{
options.TimestampFormat = "[HH:mm:ss.fff] ";
});
});
var logger = loggerFactory.CreateLogger("FlagdValidatorBug");
for (int i = 0; i < 10; i++)
{
try
{
using var cts = new CancellationTokenSource();
cts.CancelAfter(TimeSpan.FromSeconds(5));
var flagdConfig = new FlagdConfigBuilder()
.WithHost(syncEndpointUri.Host)
.WithPort(syncEndpointUri.Port)
.WithResolverType(ResolverType.IN_PROCESS) // Important! Resolver Type is 'IN_PROCESS'
.WithLogger(loggerFactory.CreateLogger("flagD"))
.Build();
var provider = new FlagdProvider(flagdConfig);
var task = Api.Instance.SetProviderAsync(provider, cts.Token)
.WaitAsync(cts.Token);
await task;
break;
}
catch (Exception ex)
{
await Api.Instance.ShutdownAsync();
logger.LogError(ex, "Exception thrown while awaiting flagd provider setup!");
}
}
var apiClient = Api.Instance.GetClient();
Api.Instance.AddHandler(ProviderEventTypes.ProviderReady, _ => logger.LogInformation("Openfeature flag provider event: ProviderReady"));
Api.Instance.AddHandler(ProviderEventTypes.ProviderError, _ => logger.LogInformation("Openfeature flag provider event: ProviderError"));
logger.LogInformation("Done!");
When I run this while having connection to the internet, everything works fine. However, I see that HttpRequestException is thrown randomly when I'm working in offline mode (i.e. laptop is not connected to any network or is connected to internal one without access to global network).
Received output:
Question from me is - why does this send a request to external source to fetch valid json schema? Shouldn't it be able to validate feature flags definition in offline mode (without having to access global network)?
Could You please elaborate on that?
Additional info
- OS version: Windows 11 Pro, v10.0.26100
- Used flagd version: flagd/v0.13.2
- Command to start flagd:
flagd.exe start --debug --uri file:./feature_flags.json --sync-port 40009 - Feature flags definition:
{
"flags": {
"TestBooleanFlag": {
"state": "ENABLED",
"variants": {
"on": true,
"off": false
},
"defaultVariant": "off",
"metadata": {
"productionStop": false,
"description": "Some description"
}
}
}
}
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels