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

Send request to network when cache entry parsing fails #321

Merged
merged 2 commits into from
Feb 26, 2020

Conversation

uhager
Copy link
Contributor

@uhager uhager commented Feb 24, 2020

Also invalidate the corrupted cache entry and set the request's entry to null.

This is probably quite rare, but we should still rather send the request to the network than keep trying to return a potentially corrupted cache entry until it expires.

@uhager uhager changed the title Parse error Send request to network when cache entry parsing fails Feb 24, 2020
@@ -159,6 +159,15 @@ void processRequest(final Request<?> request) throws InterruptedException {
new NetworkResponse(entry.data, entry.responseHeaders));
request.addMarker("cache-hit-parsed");

if (!response.isSuccess()) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

parseNetworkResponse is documented as being allowed to return null in case of an error, which means this would crash if that happens.

That being said, it seems likely that it would already crash in that situation:

  • If entry.refreshNeeded(), then it will NPE on line 181 (response.intermediate=true).
  • Otherwise, we call mDelivery.postResponse(). From there it depends on the ResponseDelivery implementation, but the default ExecutorDelivery seems like it would crash checking mResponse.isSuccess().

So maybe it's worth filing a separate bug to investigate whether we handle that scenario correctly or should just update the Javadoc to require that callers use Response.error rather than returning null?

@uhager
Copy link
Contributor Author

uhager commented Feb 26, 2020

Given that returning null crashes already, I think it's unlikely that anyone uses a Request that returns null on error. Then it seems better to update the javadoc to reflect the fact that null is already not really supported. But I'll defer to your judgement.

@jpd236 jpd236 merged commit 8a3a7ba into google:master Feb 26, 2020
@jpd236
Copy link
Collaborator

jpd236 commented Feb 26, 2020

Filed #322 for the Javadoc.

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.

2 participants