launchdarkly / dotnet-eventsource

Server-sent events (SSE) client implementation for .NET
Other
49 stars 16 forks source link

EventSource doesn't use Proxy configuration #82

Closed wags1999 closed 2 years ago

wags1999 commented 2 years ago

I'm configuring an LdClient as described in https://docs.launchdarkly.com/sdk/server-side/dotnet/migration-5-to-6#understanding-changes-to-networking:

var config =  Configuration.Builder("my-sdk-key")
    .Http(
        Components.HttpConfiguration()
            .Proxy(new System.Net.WebProxy(new Uri("http://my-proxy:8080")))
    )
    .Build();

However, when EventSource creates its HttpClient, it doesn't use the Http/Proxy configuration, resulting in errors. From the log:

INFO  LaunchDarkly.Sdk.DataSource Connecting to LaunchDarkly stream
INFO  LaunchDarkly.Sdk Waiting up to 5000 milliseconds for LaunchDarkly client to start...
DEBUG LaunchDarkly.Sdk.DataSource Making GET request to EventSource URI https://stream.launchdarkly.com/all
WARN  LaunchDarkly.Sdk Timeout encountered waiting for LaunchDarkly client initialization

The only workaround we've found is to set the global proxy as per instructions here: https://docs.microsoft.com/en-us/dotnet/framework/network-programming/proxy-configuration

.NET 4.7.2 LaunchDarkly.ServerSdk 6.1.0 LaunchDarkly.EventSource 4.1.2 LaunchDarkly.CommonSdk 5.1.0

wags1999 commented 2 years ago

Looks like I can make it work by specifying a custom MessageHandler, and that will be used by both the EventProcessor and DataSource.

var config =  Configuration.Builder("my-sdk-key")
    .Http(
        Components.HttpConfiguration()
            .MessageHandler(new HttpClientHandler() { 
                Proxy = new System.Net.WebProxy(new Uri("http://my-proxy:8080")), 
                UseProxy = true })
    )
    .Build();

Should the Proxy option be deprecated, or should EventSource be fixed to use it?

eli-darkly commented 2 years ago

I don't think the bug would be in EventSource itself, but rather, the way the SDK is constructing EventSource... since EventSource does not know anything about the SDK's configuration types and just uses whatever is passed to it. If you look at the API for this library, it does not have a separate Proxy option but relies on the caller to configure a MessageHandler with a Proxy if desired, since that is where the proxy settings really live in .NET. The SDK's Proxy option is a shortcut for doing that, but it seems the SDK is not applying it consistently.

Would you mind re-filing this in https://github.com/launchdarkly/dotnet-server-sdk/issues ?

wags1999 commented 2 years ago

Opened https://github.com/launchdarkly/dotnet-server-sdk/issues/148