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

[Cache] Handle unserialize() failures gracefully #19567

Merged
merged 1 commit into from Aug 13, 2016

Conversation

nicolas-grekas
Copy link
Member

@nicolas-grekas nicolas-grekas commented Aug 8, 2016

Q A
Branch? 3.1
Bug fix? yes
New feature? no
BC breaks? no
Deprecations? no
Tests pass? yes
Fixed tickets -
License MIT
Doc PR -

This makes fetching cached items more resilient: __PHP_Incomplete_Class "objects" and other errors triggered by unserialize should be turned to cache misses.

$isHit = false;
}
} catch (\Exception $e) {
CacheItem::log($this->logger, 'Failed to unserialize key "{key}"', array('key' => $key, 'exception' => $e));
Copy link
Contributor

Choose a reason for hiding this comment

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

It should not happen as this adapter is not cross requests (so something not unserializable won't be cached as it is not serializable as well).
If you want to keep this anyway then i guess you should use parent::unserialize below ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Ok got it it might break in case of a custom unserializer.
At least using parent::unserialize would allow you to remove the case managing false.

Copy link
Member Author

Choose a reason for hiding this comment

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

There is no parent here, and calling the same implementation would call ini_set twice for something that can't happen because as you said, this is not cross reqs

Copy link
Contributor

@GuilhemN GuilhemN Aug 9, 2016

Choose a reason for hiding this comment

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

You're right sorry, i should definitely stop reviewing on my phone...

}
} catch (\Exception $e) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Shouldn't this be moved inside the foreach to fetch as many values as possible ?

Copy link
Member Author

Choose a reason for hiding this comment

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

right, done: try/catch moved inside the foreach

@GuilhemN
Copy link
Contributor

GuilhemN commented Aug 9, 2016

LGTM 👍

@nicolas-grekas nicolas-grekas force-pushed the cache-fix-throwing-generator branch 2 times, most recently from 20184d0 to 69cfa83 Compare August 10, 2016 07:15
@fabpot
Copy link
Member

fabpot commented Aug 13, 2016

Thank you @nicolas-grekas.

@fabpot fabpot merged commit 47db638 into symfony:3.1 Aug 13, 2016
fabpot added a commit that referenced this pull request Aug 13, 2016
…grekas)

This PR was merged into the 3.1 branch.

Discussion
----------

[Cache] Handle unserialize() failures gracefully

| Q             | A
| ------------- | ---
| Branch?       | 3.1
| Bug fix?      | yes
| New feature?  | no
| BC breaks?    | no
| Deprecations? | no
| Tests pass?   | yes
| Fixed tickets | -
| License       | MIT
| Doc PR        | -

This makes fetching cached items more resilient: `__PHP_Incomplete_Class` "objects" and other errors triggered by unserialize should be turned to cache misses.

Commits
-------

47db638 [Cache] Handle unserialize() failures gracefully
@nicolas-grekas nicolas-grekas deleted the cache-fix-throwing-generator branch August 18, 2016 20:02
@fabpot fabpot mentioned this pull request Sep 3, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants