Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RemoteEvaluationClient does not work behind a proxy server #26

Closed
andrewtcobb opened this issue May 16, 2024 · 4 comments
Closed

RemoteEvaluationClient does not work behind a proxy server #26

andrewtcobb opened this issue May 16, 2024 · 4 comments

Comments

@andrewtcobb
Copy link

RemoteEvaluationClient fails to fetch user variants when running behind a proxy server.

The following error occurs:

Caused by: java.net.UnknownHostException: api.lab.amplitude.com
        at java.base/java.net.InetAddress$CachedAddresses.get(InetAddress.java:801)
        at java.base/java.net.InetAddress.getAllByName0(InetAddress.java:1533)
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1385)
        at java.base/java.net.InetAddress.getAllByName(InetAddress.java:1306)
        at okhttp3.Dns$Companion$DnsSystem.lookup(Dns.kt:49)
        at okhttp3.internal.connection.RouteSelector.resetNextInetSocketAddress(RouteSelector.kt:169)
        at okhttp3.internal.connection.RouteSelector.nextProxy(RouteSelector.kt:131)
        at okhttp3.internal.connection.RouteSelector.next(RouteSelector.kt:73)
        at okhttp3.internal.connection.ExchangeFinder.findConnection(ExchangeFinder.kt:205)
        at okhttp3.internal.connection.ExchangeFinder.findHealthyConnection(ExchangeFinder.kt:106)
        at okhttp3.internal.connection.ExchangeFinder.find(ExchangeFinder.kt:74)
        at okhttp3.internal.connection.RealCall.initExchange$okhttp(RealCall.kt:255)
        at okhttp3.internal.connection.ConnectInterceptor.intercept(ConnectInterceptor.kt:32)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.cache.CacheInterceptor.intercept(CacheInterceptor.kt:95)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.BridgeInterceptor.intercept(BridgeInterceptor.kt:83)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.http.RetryAndFollowUpInterceptor.intercept(RetryAndFollowUpInterceptor.kt:76)
        at okhttp3.internal.http.RealInterceptorChain.proceed(RealInterceptorChain.kt:109)
        at okhttp3.internal.connection.RealCall.getResponseWithInterceptorChain$okhttp(RealCall.kt:201)
        at okhttp3.internal.connection.RealCall$AsyncCall.run(RealCall.kt:517)
        at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1136)
        at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:635)

The RemoteEvaluationClient appears to be using OkHttpClient under the hood, and unfortunately OkHttpClient does not provide support for proxy settings via environment variables like many HTTP clients do. OkHttpClient provides support for proxy settings, but only programmatically via the OkHttpClient builder (see this issue for more details). As far as I know, the only way to provide proxy support would be to have RemoteEvaluationClient allow users to provide proxy settings as a part of the configuration object and pass those settings to OkHttp in order to allow the client to work behind a proxy. This is not necessary with other Amplitude SKDs I have used like the Node SDK, as their underlying HTTP clients appear to support proxy environment variables.

Are there any other workarounds you can think of in the meantime?

@bgiori
Copy link
Collaborator

bgiori commented May 20, 2024

Hi @andrewtcobb thanks for submitting this issue.

If we expose the client configuration, which settings would you add to the OkHttpClient to support the proxy? I dont think we will expose the actual builder, rather a wrapper around specific features.

@andrewtcobb
Copy link
Author

Hey @bgiori,

Thanks for looking at this. Fortunately, the OkHttpClient class accepts a proxy argument in its builder, which itself takes in a Proxy object that is used to configure proxy settings for the OkHttpClient. So I think if the Amplitude SDK allowed users to provide a Proxy object to RemoteEvaluationClient, and it then passed that along to the OkHttpClient builder, I think that would be sufficient for most use cases.

@tyiuhc
Copy link
Collaborator

tyiuhc commented May 23, 2024

@andrewtcobb, many thanks for raising this issue. You can now configure a httpProxy in RemoteEvaluationConfig. Please let us know if it is not working as expected.

@andrewtcobb
Copy link
Author

I just did a quick test and it appears to work exactly as intended. Thanks so much for adding this in!

@tyiuhc tyiuhc closed this as completed May 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants