fix(vm): release trace compression deflater - #138
Open
halibobo1205 wants to merge 1 commit into
Open
Conversation
🤖 CodeAnt AI — Review Status
|
Thanks for using CodeAnt! 🎉We're free for open-source projects. if you're enjoying it, help us grow by sharing. Share on X · |
Comment on lines
+19
to
+20
| try (MockedConstruction<Deflater> deflaters = mockConstruction(Deflater.class, | ||
| (deflater, context) -> when(deflater.finished()).thenReturn(true))) { |
There was a problem hiding this comment.
Suggestion: The construction mock forces finished() to return true, so DeflaterOutputStream.close() skips its deflation loop entirely and this test exercises only the explicit end() call. It can therefore pass even if the compression stream's finalization path is broken. Use a real deflater for the lifecycle assertion, or configure the mock to emulate the finish/deflate sequence while still verifying end(). [possible bug]
Severity Level: Major ⚠️
- ⚠️ Lifecycle test can miss compression finalization regressions.
- ⚠️ VM trace compression uses this helper at VMActuator.java:306-307.
- ❌ Future compressed traces could be corrupted despite passing tests.Steps of Reproduction ✅
1. Run `VMUtilsTest.compressShouldReleaseDeflater()` at
`actuator/src/test/java/org/tron/core/vm/VMUtilsTest.java:17-25`; the test invokes the
public `VMUtils.compress(byte[])` helper directly.
2. `VMUtils.compress()` constructs a `DeflaterOutputStream` at
`actuator/src/main/java/org/tron/core/vm/VMUtils.java:112-127`, and `write()` closes that
stream through its `finally` block at `VMUtils.java:101-104`.
3. The construction mock at `VMUtilsTest.java:19-20` forces `Deflater.finished()` to
return `true`. Consequently, `DeflaterOutputStream.close()` can skip its normal deflation
loop after calling `finish()`, so the test does not exercise actual output finalization or
deflate progress.
4. A regression in the stream's finish/deflate interaction could therefore still satisfy
`verify(...).end()` at `VMUtilsTest.java:23-24`. The separate content test at
`VMUtilsTest.java:28-33` checks successful compression with a real `Deflater`, but it does
not verify that the constructed deflater in the lifecycle test is finalized and released
along the same execution path. Use a real deflater for the lifecycle assertion, or
configure the mock to emulate the finish/deflate sequence while retaining verification of
`end()`.(Use Cmd/Ctrl + Click for best experience)
Prompt for AI Agent 🤖
This is a comment left during a code review.
**Path:** actuator/src/test/java/org/tron/core/vm/VMUtilsTest.java
**Line:** 19:20
**Comment:**
*Possible Bug: The construction mock forces `finished()` to return `true`, so `DeflaterOutputStream.close()` skips its deflation loop entirely and this test exercises only the explicit `end()` call. It can therefore pass even if the compression stream's finalization path is broken. Use a real deflater for the lifecycle assertion, or configure the mock to emulate the finish/deflate sequence while still verifying `end()`.
Validate the correctness of the flagged issue. If correct, How can I resolve this? If you propose a fix, implement it and please make it concise.
Once fix is implemented, also check other comments on the same PR, and ask user if the user wants to fix the rest of the comments as well. if said yes, then fetch all the comments validate the correctness and implement a minimal fix
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
User description
What does this PR do?
Explicitly releases the
Deflatercreated for VM trace compression.DeflaterOutputStreamdoes not release an externally suppliedDeflater, so the instance must be ended by its owner. The compression helper now callsDeflater.end()in afinallyblock, covering both successful and exceptional execution paths.This PR also adds tests to verify:
Deflateris explicitly released.Additional context
VMConfig.vmTraceCompressed()currently always returns its default value offalsebecause there is no setter or configuration-loading path. Therefore, the compression branch is not reached through the normal VM trace workflow today.The resource-management issue still exists in the public compression helper and would become active if compression is enabled or the helper is called directly. This PR fixes the lifecycle issue without enabling compression or changing the existing VM trace format.
Testing