launchdarkly / ios-client-sdk

LaunchDarkly Client-side SDK for iOS (Swift and Obj-C)
https://docs.launchdarkly.com/sdk/client-side/ios
Other
70 stars 85 forks source link

LDStreamingMode.streaming incompatible with some Proxy servers #406

Open swhitty opened 2 months ago

swhitty commented 2 months ago

Describe the bug LDStreamingMode.streaming can cause start() / setOnline(true) to timeout behind some proxy servers.

We observe that 2% of our customers appear to be behind proxy servers that cause this issue. While cached flags values are available, falling back to polling mode is more reliable for these users.

To reproduce

Add device to a network with an incompatible proxy server and attempt start in streaming mode (which is default):

var config = LDConfig(mobileKey: "")
config.startOnline = false
config.streamingMode = .streaming
LDClient.start(config: config, context: context, startWaitSeconds: 5) { timedOut in
   ...
}

Request is sent to https://clientstream.launchdarkly.com and headers are returned but no data is ever received within the body, timeout occurs and completion handler is called.

Expected behavior It would be great to detect this and switch to polling somehow.

It's unclear how one could try with streaming then fall back to polling. Its possible to use CFNetworkCopyProxiesForURL to detect upfront if the config.streamingURL will be handled via a proxy, this

Logs If applicable, add any log output related to your problem.

Library version 9.8.2

XCode and Swift version Xcode 15.4 Swift 5.10

Platform the issue occurs on iOS

tanderson-ld commented 2 months ago

Hi @swhitty. We are currently working through some designs for supporting multiple datasources with prioritization and fallback mechanisms. We will keep your situation in mind as we work through those designs.

We definitely prefer customers to use streaming, but in your situation, could you help us understand why using polling is prohibitive?

Does your application get used in an environment where Proxies are more prevalent in your opinion? I don't know off the top of my head what the prevalence of Proxy usage in the iOS ecosystem is. If it is true that 2% of all global iOS users are using proxies, that is significant and we will want to dig more.

swhitty commented 2 months ago

We prefer to use streaming because it works great for 97% of our users and is highly responsive in broadcasting changes.

We find that 3% of our users receive a timeout when attempting to connect Launch Darkly in streaming mode and therefore operate on cached flag values. We know that some of these users are behind a proxy server that appears to be incompatible with the Launch Darkly streaming connection.

We don't want to switch every user to polling, we would like to improve the experience for these 3% of users without degrading the experience for the 97% where it works great.

swhitty commented 3 weeks ago

I've collected some data over the past month and 2.8% of our ~1M users have been behind a proxy server at least once.

tanderson-ld commented 2 weeks ago

Thank you for that data point.

tanderson-ld commented 2 weeks ago

How are you positively identifying that the customer is behind a proxy? Could you customize those customers to use polling if you can detect it beforehand as a workaround for the time being?

swhitty commented 2 weeks ago

We are using CFNetworkCopyProxiesForURL to detect upfront if the config.streamingURL will be handled via a proxy and preemptively using polling for these users.