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

Prevent corruption of memory cache #1136

Merged
merged 3 commits into from
Oct 28, 2020
Merged

Prevent corruption of memory cache #1136

merged 3 commits into from
Oct 28, 2020

Conversation

sdrave
Copy link
Member

@sdrave sdrave commented Oct 27, 2020

This PR changes the behavior of MemoryRegion to always make a deepcopy of any values stored in the cache and to only return deep copies of the values contained in the cache. While this may increase the memory footprint and somewhat hurt performance, it seems like the only way to make using MemoryRegion really safe. The practical impact of the increased memory usage should be quite small, IMHO.

Note that the current provisions of returning copies of VectorArrays and making NumPy arrays immutable had no effect since all values stored in the cache are actually 2-tuples.

See #1133 for a non-obvious real world example of MemoryRegion being corrupted.

@sdrave sdrave added the pr:fix Fixes a bug label Oct 27, 2020
@sdrave sdrave added this to the 2020.2 milestone Oct 27, 2020
@sdrave sdrave requested a review from ftalbrecht October 27, 2020 14:30
@sdrave sdrave mentioned this pull request Oct 27, 2020
Copy link
Member

@renefritze renefritze left a comment

Choose a reason for hiding this comment

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

Could we try to trim down @ftalbrecht's example code that exhibited the error and add it as a test case?

@sdrave sdrave requested a review from renefritze October 27, 2020 15:15
@sdrave
Copy link
Member Author

sdrave commented Oct 27, 2020

@renefritze, the Enforce PR labels thing is failing again. We had similar issues some time ago. Maybe we should disable it?

@codecov
Copy link

codecov bot commented Oct 27, 2020

Codecov Report

Merging #1136 into master will increase coverage by 0.02%.
The diff coverage is 100.00%.

Impacted Files Coverage Δ
src/pymor/core/cache.py 86.36% <100.00%> (+0.72%) ⬆️
src/pymor/core/base.py 94.80% <0.00%> (+0.64%) ⬆️
src/pymor/models/basic.py 88.88% <0.00%> (+3.17%) ⬆️

@renefritze
Copy link
Member

@renefritze, the Enforce PR labels thing is failing again. We had similar issues some time ago. Maybe we should disable it?

Lets see if the update fixing the run first

Copy link
Contributor

@ftalbrecht ftalbrecht left a comment

Choose a reason for hiding this comment

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

I have no better suggestion than deep copy, looks good.

@renefritze renefritze merged commit 1990f35 into master Oct 28, 2020
@renefritze renefritze deleted the fix_memory_cache branch October 28, 2020 13:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
pr:fix Fixes a bug
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants