Skip to content

fix(vm): release trace compression deflater - #138

Open
halibobo1205 wants to merge 1 commit into
developfrom
codex/fix-vm-trace-deflater-release
Open

fix(vm): release trace compression deflater#138
halibobo1205 wants to merge 1 commit into
developfrom
codex/fix-vm-trace-deflater-release

Conversation

@halibobo1205

@halibobo1205 halibobo1205 commented Jul 28, 2026

Copy link
Copy Markdown
Owner

User description

What does this PR do?

Explicitly releases the Deflater created for VM trace compression.

DeflaterOutputStream does not release an externally supplied Deflater, so the instance must be ended by its owner. The compression helper now calls Deflater.end() in a finally block, covering both successful and exceptional execution paths.

This PR also adds tests to verify:

  • The Deflater is explicitly released.
  • Compressed VM trace content can still be decompressed without data loss.

Additional context

VMConfig.vmTraceCompressed() currently always returns its default value of false because 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

./gradlew :actuator:test --tests org.tron.core.vm.VMUtilsTest


___

## **CodeAnt-AI Description**
Release compression resources safely without changing VM trace content

### What Changed
- VM trace compression now releases its compression resource after both successful and failed operations
- Compressed trace data remains fully recoverable without content loss
- Added coverage for resource release and compression round trips

### Impact
`✅ Fewer compression resource leaks`
`✅ Reliable VM trace decompression`
`✅ Safer failure handling during trace compression`
<details><summary><strong>💡 Usage Guide</strong></summary>

### Checking Your Pull Request
Every time you make a pull request, our system automatically looks through it. We check for security issues, mistakes in how you're setting up your infrastructure, and common code problems. We do this to make sure your changes are solid and won't cause any trouble later.

### Talking to CodeAnt AI
Got a question or need a hand with something in your pull request? You can easily get in touch with CodeAnt AI right here. Just type the following in a comment on your pull request, and replace "Your question here" with whatever you want to ask:
<pre>
<code>@codeant-ai ask: Your question here</code>
</pre>
This lets you have a chat with CodeAnt AI about your pull request, making it easier to understand and improve your code.

#### Example
<pre>
<code>@codeant-ai ask: Can you suggest a safer alternative to storing this secret?</code>
</pre>

### Preserve Org Learnings with CodeAnt
You can record team preferences so CodeAnt AI applies them in future reviews. Reply directly to the specific CodeAnt AI suggestion (in the same thread) and replace "Your feedback here" with your input:
<pre>
<code>@codeant-ai: Your feedback here</code>
</pre>
This helps CodeAnt AI learn and adapt to your team's coding style and standards.

#### Example
<pre>
<code>@codeant-ai: Do not flag unused imports.</code>
</pre>

### Retrigger review
Ask CodeAnt AI to review the PR again, by typing:
<pre>
<code>@codeant-ai: review</code>
</pre>

### Check Your Repository Health
To analyze the health of your code repository, visit our dashboard at [https://app.codeant.ai](https://app.codeant.ai). This tool helps you identify potential issues and areas for improvement in your codebase, ensuring your repository maintains high standards of code health.

</details>

@codeant-ai

codeant-ai Bot commented Jul 28, 2026

Copy link
Copy Markdown

🤖 CodeAnt AI — Review Status

Status Commit Started (UTC) Finished (UTC)
✅ Reviewed your PR 5d5f321 Jul 28, 2026 · 09:20 09:23

@codeant-ai

codeant-ai Bot commented Jul 28, 2026

Copy link
Copy Markdown

Thanks for using CodeAnt! 🎉

We're free for open-source projects. if you're enjoying it, help us grow by sharing.

Share on X ·
Reddit ·
LinkedIn

@codeant-ai codeant-ai Bot added the size:M This PR changes 30-99 lines, ignoring generated files label Jul 28, 2026
Comment on lines +19 to +20
try (MockedConstruction<Deflater> deflaters = mockConstruction(Deflater.class,
(deflater, context) -> when(deflater.finished()).thenReturn(true))) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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()`.

Fix in Cursor Fix in VSCode Claude

(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
👍 | 👎

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant