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

Latest version doesn't connect to the server properly [4.1.0] #87

Open
rubenquadros12 opened this issue May 29, 2023 · 4 comments
Open

Comments

@rubenquadros12
Copy link

rubenquadros12 commented May 29, 2023

Hi,

I'm using version 4.1.0 of the library.

I'm calling eventsource.start() method to connect to the server.
I see that the library internally calls call.execute()

This call.execute() doesn't return anything and no code after this line gets executed.
I have debugged the code, there are no exceptions.

I'm making both init and connect call in a IO Dispatcher.

The funny thing is if I attach HttpLoggingInterceptor I can see 200 for the api call.

I have tried by calling eventsource.readAnyEvent() as well which internally connects to the server first and it's the same result.

My code snippets:

This is init call:


private var source: EventSource? = null

val uri = URI.create(url)
val connectStrategy = HttpConnectStrategy.http(uri).httpClient(okHttpClient) //my custom client
val eventSourceBuilder = EventSource.Builder(connectStrategy)
      .errorStrategy(ErrorStrategy.alwaysThrow())
      .logger(LDLogger.withAdapter(rtcLogger, TAG)) //my custom logger
      .retryDelay(realTimeEventsConfig.reconnectTimeInSeconds, TimeUnit.SECONDS)
      .retryDelayStrategy(
                DefaultRetryDelayStrategy.defaultStrategy().maxDelay(
                    realTimeEventsConfig.maxReconnectTimeInSeconds, TimeUnit.SECONDS)
        )

source = eventSourceBuilder.build()

Connect call:

try {
     disconnect(shouldClear = false)
     source?.start()
} catch (e: Exception) {
      //log exception
 }

Can you please let me know what can be the issue?

Edit: If I dont use custom http client it works

@rubenquadros12 rubenquadros12 changed the title Latest version doesn't connect to the server properly Latest version doesn't connect to the server properly [4.1.0] May 29, 2023
@tanderson-ld
Copy link
Contributor

Hi @rubenquadros12 , thank you for reporting this issue. We have filed it internally as 205140. I'm not sure when one of our engineers will get a chance to investigate, but we'll update this issue when we do. Thank you.

@hiteshchopra11
Copy link

Hey @tanderson-ld, thanks for responding. We have identified what caused the issue. Actually it was related to one of the interceptors used by the Okhttp client inside our app. Very similar to this issue, we noticed that one of the interceptors added in the Okhttp client, uses response.peekBody(Long.MAX_VALUE) , which does the following :

Peeks up to byteCount bytes from the response body and returns them as a new response body. If fewer than byteCount bytes are in the response body, the full response body is returned. If more than byteCount bytes are in the response body, the returned value will be truncated to byteCount bytes.

After removing this interceptor from the okhttp client, the connection is successful. Is this an intended behaviour of the library?

@tanderson-ld
Copy link
Contributor

We don't intend to behave a certain way based on externally added interceptors, but perhaps it was leading to modification of the data our code was receiving? I haven't had a change to dig in deeper yet on how peek could interfere. It doesn't seem like it should.

@henryngcw
Copy link

@hiteshchopra11 Would be very appreciated if you would kindly guide me on how to remove okhttp client interceptor?

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

4 participants