-
Notifications
You must be signed in to change notification settings - Fork 9.2k
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
IllegalArgumentException for the url in the Cache Entry #6453
Comments
@brunoescalona thanks for the additional debug information. |
Yes I'd like to get to root cause on this one too! @brunoescalona I don't see a cache configured in your example. Is that happening elsewhere? Is it possible to provide a minimal test or code sample that you can reliably reproduce with? |
@dave-r12 I have updated the description with a more detailed and similar configuration. But I also can include it here below. We can not reproduce the issue, we tried different things but it was impossible so far. After few ideas I could only simulate the behaviour of the issue "corrupting" manually the cache files and that way I was able to get the same stack trace and error, but I couldn't reproduce the root cause and understand why the cache file was corrupted. We are also happy to provide more detailed information with few production endpoints causing the issue in a private channel if needed. We are currently using two Okhttp instances configured as follow:
|
I can confirm that we have the same issue, see it on clients with cache. And it's not an issue of request itself, we have a debug and request URL is correct, so after digging into sources, it may happen only if a cache entry has invalid value for URL Never be able to reproduce it, only on prod. We have not so many such cases, 10-30 per day maximum, but still it in top 10 our crashes |
We've been also getting the exact same crash, and the count is now getting higher and higher. Is there any way to suppress it or to solve it? |
@im-lakshya is there any additional context here? Is it all Android versions? Any chance you have multiple clients sharing a cache? |
We're one of the libraries in which we use Picasso for image caching. And our users suspect that the crash is happening because of us and I'm not able to find out the root cause behind it, and also verified that Picasso is also internally catching the exceptions when it makes connections via OkHttp. And the crash is happening across all the major versions (9, 10, 11) but I can see that 90% of crashes are happening in Android 10 devices. We also checked that there are multiple libraries present in the client's app which internally uses OkHttp. So we're not sure how do we ensure which library is causing this crash, or is it OkHttp doing something internally due to which it is crashing. Let me know if you require any more information, I'll try to get them from the client. |
Thanks for the info. So far, I haven't been able to spot how this could happen in practice. It seems .... impossible 😄. But there's gotta be an explanation! This person had mentioned that when they read the cache file directly upon seeing this exception the first line was actually fine #3251 (comment). Could anyone else confirm if reading the cache file directly after seeing this exception shows a valid URL as the first line? |
Anything we could put in the next release to confirm a theory? Or recover at least enough to make this non-fatal?
|
@dave-r12 we were reporting the URL for each crash from here:
And the urls are corrupted. I didn't go through all the code, but I was expecting to have the text url obtained from the cache file directly. Should we also try to read the file to compare the url stored there? @yschimke where are you planning to include that check? |
@brunoescalona not sure, I'm brainstorming what we can do in Version+1, to get information to resolve by Version+2. And wondering if we should ask for reports and also make it not fatal until then. |
We see this crash on all versions of Android, but ~70-80% are from Android 10. And we indeed reuse cache between multiple okhttp clients. I will try to split http cache for every client (it's not really reused, it probably never request the same url, only reuses cache dir) and let you know |
Are you creating multiple Cache instances that all point at the same directory? That might be your problem. You want a single Cache instance that the different OkHttpClient instances all share. |
@swankjesse No, we create a single Cache instance which used by multiple clients. |
@brunoescalona an example we could check, print a noisy warning if we create two cache instances with same directory. |
I'm stuck in the same issue and I find that it occurs if you try to make a URL with more than 1 period in the domain. |
@yschimke we included some logs when the cache object is instantiated. After checking few logs of the affected users I could see that the cache is instantiated only once. Can we do something else to help? Edit: by the way @yschimke we are using dagger to instantiate the cache and we are using the @singleton annotation. |
We've been impacted by this issue for quite a while now and after adding more logs here is what we found on our side: We added a
A potential loophole would be something modifing the |
+1 to your PR, but it seems to confirm we are correctly failing already. Running HttpUrlGetTest (which extends HttpUrlTest) shows the right failure.
|
Test case related to cache corruption found in #6453
Can this be worked on? |
If you are willing to try OkHttp 5.0 alphas then you could put in place Cache FileSystem logging, and try to show where the problem is happening. See https://github.com/square/okhttp/pull/6550/files Maybe on each meaningful cache even printing the first line of the file and watching for when the corruption happens. |
We have an interceptor that catches the issue and deletes the cache entry. It's not pretty, but maybe it'll help y'all as well: |
Same exact problem and not a single clue what to look for. |
we update okHttp version to 4.9.1 , and have same issues , |
In change log for Version 5.0.0-alpha.2 I see
Is that fix for this issue? If yes how long we will wait stable 5.0.0 version? And is it possible to fix it in version 4.9.x?=) |
A |
I see the backport was just merged #6940 to |
any corrections? |
Any corrections ? Been waiting for a while now .. |
Any corrections? @yschimke |
The fix (#6495 and #6940) makes it much more difficult to attempt to recover from this state using something like @danh32 's Of course a recovery mechanism built into OkHttp (#3251) would be great, but in the meantime is there another way to attempt to recover? I suppose we could install a For some context - of the many endpoints my app hits, only ~2 are actually cacheable and we hit those two very frequently. The cache being broken for them can mean hundreds of additional calls. I have no problem just deleting the entire cache right now if we detect it is corrupted 😆 |
Unfortunately for us, our own sanitization step (very similar to It looks like this for each request, before calling
private fun Cache.sanitize(request: Request) {
kotlin.runCatching {
invoke("get", request)
}.onFailure {
if (it !is InvocationTargetException) return
kotlin.runCatching {
invoke("remove", request)
}
}
} |
Hello any news about this issue ? |
any corrections? it happens only in production when using "minifyEnabled true" for obfuscation, and "-keep class okhttp3.**{*;}" didn't help to avoid this issue - Do any idea? |
Hello, |
I used the OkGo library in the project, which used okhttp-3.8.1, and this error also occurred. After tracing, the error originated from line 1319 of the 'okhttp3. HttpUrl -->parse()' method. Scenario: In the 'get' request, a 'CODED-CONTENT' returned by com. yzq. zxinglibrary. android. CaptureActivity was passed in, which is a URL. I directly passed the reference to 'CODED-CONTENT' into the 'get' method. When 'CODED-CONTENT' is 'http://ip:port/xxx‘ This error will occur. I hope my analysis process is useful to you |
Possible factors: terms of settlement: |
is there new update related to this one ? |
I can confirm that with the newest okhttp alpha version 5.0.0-alpha.12, it's fixed - https://square.github.io/okhttp/changelogs/changelog/#version-500-alpha12 . Please check the change log. |
Yep:
|
The following error is one of our main crashes right now, around 25% of our crashes.
The same error was reported #4322 and #4918
I would like to reopen the discussion and maybe together we can find the root cause and a solution.
During the last week we were building a custom version based on the
4.9.0
to report the url contained in the Cache Entry. We modified the following line with the code below and we also modified the cache path directory to avoid possible old corrupted files.We are getting in that case the corrupted url stored in the cache file.
For example, with the following retrofit configuration:
We are getting in the error stack traces the following urls:
The url stored in the cache file, as you can see, can contain some corrupted text or the
https
is removed from the url.Could you have a look? I can also investigate further or give you more data if needed.
Regards
The text was updated successfully, but these errors were encountered: