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

Fail earlier on cache corruptions #6495

Merged
merged 6 commits into from Jan 9, 2021
Merged

Conversation

yschimke
Copy link
Collaborator

Fail earlier on cache corruption, log warning instead of failing terminally.

@@ -1258,7 +1258,7 @@ class HttpUrl internal constructor(
this.scheme = base.scheme
} else {
throw IllegalArgumentException(
"Expected URL scheme 'http' or 'https' but no colon was found")
"Expected URL scheme 'http' or 'https' but no scheme was found for $input")
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Happy to drop this for PII reasons if there is concern, although as a corrupted url, the debug value seems higher than normal.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log up to 6 characters? Like www.ex... ?

val urlLine = source.readUtf8LineStrict()
// Choice here is between failing with a correct RuntimeException
// or mostly silently with an IOException
url = urlLine.toHttpUrlOrNull() ?: throw IOException("Cache Failure for $urlLine").also {
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

3 options here

  1. runtime exception - fatal...
  2. io exception only
  3. io exception and log a warning

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change cache failure to cache corruption ?

@@ -1258,7 +1258,7 @@ class HttpUrl internal constructor(
this.scheme = base.scheme
} else {
throw IllegalArgumentException(
"Expected URL scheme 'http' or 'https' but no colon was found")
"Expected URL scheme 'http' or 'https' but no scheme was found for $input")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Log up to 6 characters? Like www.ex... ?

val urlLine = source.readUtf8LineStrict()
// Choice here is between failing with a correct RuntimeException
// or mostly silently with an IOException
url = urlLine.toHttpUrlOrNull() ?: throw IOException("Cache Failure for $urlLine").also {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change cache failure to cache corruption ?

@yschimke yschimke merged commit 5396f41 into square:master Jan 9, 2021
@yschimke yschimke deleted the cache_corruption branch January 30, 2021 14:09
@Thomas-Vos
Copy link

Could this fix be backported to 4.9.x, please?

yschimke added a commit to yschimke/okhttp that referenced this pull request Nov 28, 2021
swankjesse pushed a commit that referenced this pull request Nov 29, 2021
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

Successfully merging this pull request may close these issues.

None yet

3 participants