Skip to content

fix(config): close resource streams - #55

Closed
Federico2014 wants to merge 2 commits into
release_v4.8.3from
fix/resource-streams-v4.8.3
Closed

Federico2014 wants to merge 2 commits into
release_v4.8.3from
fix/resource-streams-v4.8.3

Conversation

@Federico2014

@Federico2014 Federico2014 commented Sep 22, 2026 •

Copy link
Copy Markdown
Owner

What does this PR do?

Closes streams used for Git metadata and zk parameter loading, avoids opening a stream just to locate configuration resources, and closes directory-walk streams in plugin copy utilities and affected tests. Missing zk parameter resources now produce an explicit error.

Why are these changes required?

Unclosed streams can retain file or directory handles during repeated operations and cause resource exhaustion or platform-dependent failures.

This PR has been tested by:

  • 62 focused Framework and Plugins tests passed on macOS x86_64 with JDK 8.
  • Framework main/test and Plugins main Checkstyle passed.
  • Manual Testing: Not performed.

Follow up

None.

Extra details

Fixes resource-stream handling on release_v4.8.3. Skips GetTransactionByIdSolidityServletTest because the release branch already replaced its file-based response handling, and preserves the updated error-response assertion in BroadcastServletTest.

Port the remaining changes from #48 (9bbf15f).

Skip GetTransactionByIdSolidityServletTest because release_v4.8.3 replaced its file-backed response handling in 0d19485. Preserve the updated BroadcastServletTest error-response assertion.
@coderabbitai

coderabbitai Bot commented Sep 22, 2026 •

Copy link
Copy Markdown

Important

Review skipped

Auto reviews are disabled on base/target branches other than the default branch.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Advanced

Run ID: bcdebf09-29b6-4bac-9b80-e9adcdb63398

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Use the checkbox below for a quick retry:

  • 🔍 Trigger review

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@cubic-dev-ai cubic-dev-ai Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

All reported issues were addressed across 6 files

Reply with feedback, questions, or to request a fix.

Re-trigger cubic

Comment thread framework/src/main/java/org/tron/core/zen/ZksnarkInitService.java

@cubic-dev-ai cubic-dev-ai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

1 issue found across 2 files (changes from recent commits).

Prompt for AI agents (unresolved issues)

Check if these issues are valid — if so, understand the root cause of each and fix them. If appropriate, use sub-agents to investigate and fix each issue separately.


<file name="plugins/src/main/java/common/org/tron/plugins/utils/FileUtils.java">

<violation number="1" location="plugins/src/main/java/common/org/tron/plugins/utils/FileUtils.java:174">
P2: `copyTree` walks with `FileVisitOption.FOLLOW_LINKS`, and `copy` then uses `Files.copy`, which also follows links by default. A symlink inside a database directory that points outside the source tree copies/traverses content from outside the intended subtree, and a symlink cycle makes `Files.walk` throw `FileSystemLoopException`. Because `copyDatabases`/`copyDir` wrap any `IOException` in a `RuntimeException`, a single cycle aborts the entire multi-directory copy and leaves a partial destination in the backup/archive path. This behavior carried over from the pre-PR code, but the new shared `copyTree` is the right place to harden it: walk without following links (`Files.walk(Paths.get(src.toString(), dir))`), or switch to `Files.walkFileTree` with explicit `visitFile`/cycle detection if symlinked directories inside the tree are intentional.</violation>
</file>

Reply with feedback, questions, or to request a fix.

Re-trigger cubic


private static void copyTree(Path src, Path dest, String dir) throws IOException {
try (Stream<Path> paths = Files.walk(
Paths.get(src.toString(), dir), FileVisitOption.FOLLOW_LINKS)) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2: copyTree walks with FileVisitOption.FOLLOW_LINKS, and copy then uses Files.copy, which also follows links by default. A symlink inside a database directory that points outside the source tree copies/traverses content from outside the intended subtree, and a symlink cycle makes Files.walk throw FileSystemLoopException. Because copyDatabases/copyDir wrap any IOException in a RuntimeException, a single cycle aborts the entire multi-directory copy and leaves a partial destination in the backup/archive path. This behavior carried over from the pre-PR code, but the new shared copyTree is the right place to harden it: walk without following links (Files.walk(Paths.get(src.toString(), dir))), or switch to Files.walkFileTree with explicit visitFile/cycle detection if symlinked directories inside the tree are intentional.

Prompt for AI agents
Check if this issue is valid — if so, understand the root cause and fix it. At plugins/src/main/java/common/org/tron/plugins/utils/FileUtils.java, line 174:

<comment>`copyTree` walks with `FileVisitOption.FOLLOW_LINKS`, and `copy` then uses `Files.copy`, which also follows links by default. A symlink inside a database directory that points outside the source tree copies/traverses content from outside the intended subtree, and a symlink cycle makes `Files.walk` throw `FileSystemLoopException`. Because `copyDatabases`/`copyDir` wrap any `IOException` in a `RuntimeException`, a single cycle aborts the entire multi-directory copy and leaves a partial destination in the backup/archive path. This behavior carried over from the pre-PR code, but the new shared `copyTree` is the right place to harden it: walk without following links (`Files.walk(Paths.get(src.toString(), dir))`), or switch to `Files.walkFileTree` with explicit `visitFile`/cycle detection if symlinked directories inside the tree are intentional.</comment>

<file context>
@@ -138,43 +138,44 @@ public static boolean isSymbolicLink(File file) throws IOException {
+
+  private static void copyTree(Path src, Path dest, String dir) throws IOException {
+    try (Stream<Path> paths = Files.walk(
+        Paths.get(src.toString(), dir), FileVisitOption.FOLLOW_LINKS)) {
+      paths.forEach(source -> copy(source, dest.resolve(src.relativize(source))));
+    }
</file context>
Suggested change
Paths.get(src.toString(), dir), FileVisitOption.FOLLOW_LINKS)) {
try (Stream<Path> paths = Files.walk(Paths.get(src.toString(), dir))) {

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant