Improve a potential out-of-memory edge case in CowData
by propagating errors out of _copy_on_write
.
#100672
+32
−29
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I am not making much progress on #100619, so I'm making another small PR about an inconsistency in the
CowData
class that I noticed while spending so much quality time with it.It's an edge case where
_copy_on_write
fails to allocate a new buffer (out of memory).Previously, the error was logged, the non-1 refcount was ignored, and the shared data may have been reallocated in later instructions, possibly invalidating it for other owners.
Instead, this PR changes behavior such that an out-of-memory error is recognized and propagated upwards, such that no shared data is invalidated.
This is unlikely to have an effect during most runs, but it may improve error behavior in very rare edge cases.
The return value of
_copy_on_write
was previously ignored in all other spots, and still is with the new code. In those cases, it is likely that shared data is overwritten as a result (though not completely invalidated as in theresize
case).