Skip to content
This repository has been archived by the owner on Jul 27, 2023. It is now read-only.

Fix blocking query read timeout issue #289

Merged
merged 6 commits into from
Dec 27, 2017
Merged

Fix blocking query read timeout issue #289

merged 6 commits into from
Dec 27, 2017

Conversation

yfouquet
Copy link
Collaborator

@yfouquet yfouquet commented Dec 27, 2017

This PR aims at resolving the read timeout issue for caches (issues #255 and #202)
Using Interceptor (OkHttp > 3.9.0), the timeout can be adjusted depending on the url.
IMO, this is an elegant solution has not change is required for users.

An alternative would have been to use the @headers annotation in the retrofit api, together with a OkHttp interceptor to check the header and adjust the timeout. However, some queries are used for both cache and standard API call, and so queries would need to be duplicated, ...

What has been done:

  1. Decrease OkHttp read timeout to 2 second as the default value of OkHttp (10 seconds) is a very long duration when we consider testing.
  2. Making ConsulCache AutoCloseable makes it easier to write tests for caches
  3. Add tests for Key/Value cache. The tests shows the issue with the timeout.
  4. Add an interceptor to adjust the read timeout depending on the url.
  5. Activate the feature. In order to ensure compatibility, this feature can easily be switched off.

@yfouquet
Copy link
Collaborator Author

Hi @rickfast ,
I'd like to have your opinion on this PR as alternatives exist.

Currently, the read timeout is the default value of okhttp i.e. 10 seconds.
That is a very long duration when we consider testing.
Decreasing it to 2 second should have limited to no impact.
This is useful for test purposes.
@rickfast
Copy link
Owner

I like it. Rebase it and I’ll merge it. I’ve had a lot of requests and complaints regarding the mismatch between http timeouts and blocking consul waits

The first test checks that the cache is notified at startup.
The second test checks cache notifications for blocking queries of 1 and 10 seconds.
Note that it is successful for 1 sec (<readTime) but failing for 10 sec.
This "interceptor" is required to extract the wait query parameter from the url.
Then, it adjusts the OkHttp read timeout accordingly.
This feature requires OkHttp 3.9.0 which has been already added to retrofit2, but not yet release.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants