Skip to content

Fix file descriptor leaks in ServerStatusManager - #1331

Merged
minwoox merged 1 commit into
line:mainfrom
minwoox:close_fd
Jul 13, 2026
Merged

Fix file descriptor leaks in ServerStatusManager#1331
minwoox merged 1 commit into
line:mainfrom
minwoox:close_fd

Conversation

@minwoox

@minwoox minwoox commented Jul 10, 2026

Copy link
Copy Markdown
Contributor

Motivation:

Files.newInputStream() and Files.newOutputStream() allocate real OS file descriptors. Properties.load() and Properties.store() do not close the stream passed to them, so the caller is responsible for closing it. The descriptors are eventually reclaimed by GC, but GC is triggered by memory pressure rather than FD exhaustion.

Modifications:

  • ServerStatusManager.serverStatus(): wrap Files.newInputStream() in try-with-resources so the stream is closed after Properties.load().
  • ServerStatusManager.updateStatus(): same fix for the load path; also wrap Files.newOutputStream() in try-with-resources so the stream is closed after Properties.store().

Result:

  • File descriptors opened for property file I/O are now released deterministically instead of relying on GC finalisation.

…Executor

Motivation:

`Files.newInputStream()` and `Files.newOutputStream()` allocate real OS
file descriptors. `Properties.load()` and `Properties.store()` do not
close the stream passed to them, so the caller is responsible for
closing it. The descriptors are eventually reclaimed by GC, but GC is
triggered by memory pressure rather than FD exhaustion.

Modifications:

- `ServerStatusManager.serverStatus()`: wrap `Files.newInputStream()`
  in try-with-resources so the stream is closed after `Properties.load()`.
- `ServerStatusManager.updateStatus()`: same fix for the load path;
  also wrap `Files.newOutputStream()` in try-with-resources so the
  stream is closed after `Properties.store()`.

Result:

- File descriptors opened for property file I/O are now released
  deterministically instead of relying on GC finalisation.
@minwoox minwoox added this to the 0.85.0 milestone Jul 10, 2026
@minwoox
minwoox marked this pull request as ready for review July 10, 2026 10:06
@minwoox
minwoox requested review from ikhoon and jrhee17 as code owners July 10, 2026 10:06
@coderabbitai

coderabbitai Bot commented Jul 10, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

The pull request updates file IO in replay revision and server status handling to use Java try-with-resources, while preserving existing revision-file and status-property behavior.

Changes

File resource management

Layer / File(s) Summary
Replay revision file reading
server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java
getLastReplayedRevision() closes the revision-file reader automatically and retains -1 for a missing file.
Server status property IO
server/src/main/java/com/linecorp/centraldogma/server/management/ServerStatusManager.java
serverStatus() and updateStatus(...) use auto-closed input and output streams for loading and storing status properties.

Estimated code review effort: 2 (Simple) | ~10 minutes

Possibly related PRs

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing file descriptor leaks in ServerStatusManager.
Description check ✅ Passed The description matches the code changes and accurately explains the try-with-resources fix for stream cleanup.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai 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.

🧹 Nitpick comments (1)
server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java (1)

775-775: 📐 Maintainability & Code Quality | 🔵 Trivial | 💤 Low value

Specify UTF-8 charset in InputStreamReader for consistency with the write path.

updateLastReplayedRevision (line 789) writes using StandardCharsets.UTF_8, but getLastReplayedRevision reads via new InputStreamReader(new FileInputStream(...)) which uses the platform default charset. This is a pre-existing inconsistency, not introduced by this PR, and is practically harmless for numeric strings. Since this method is being touched, consider aligning the charset.

♻️ Optional charset alignment
-        try (BufferedReader br = new BufferedReader(new InputStreamReader(new FileInputStream(revisionFile)))) {
+        try (BufferedReader br = new BufferedReader(
+                new InputStreamReader(new FileInputStream(revisionFile), StandardCharsets.UTF_8))) {
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In
`@server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java`
at line 775, In getLastReplayedRevision, update the InputStreamReader
construction to explicitly use StandardCharsets.UTF_8, matching the charset used
by updateLastReplayedRevision when writing the revision file.
🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Nitpick comments:
In
`@server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java`:
- Line 775: In getLastReplayedRevision, update the InputStreamReader
construction to explicitly use StandardCharsets.UTF_8, matching the charset used
by updateLastReplayedRevision when writing the revision file.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: CHILL

Plan: Pro

Run ID: 6b5f33d7-710c-4be1-91a3-015128dc44c6

📥 Commits

Reviewing files that changed from the base of the PR and between 99db9ec and ac62ae7.

📒 Files selected for processing (2)
  • server/src/main/java/com/linecorp/centraldogma/server/internal/replication/ZooKeeperCommandExecutor.java
  • server/src/main/java/com/linecorp/centraldogma/server/management/ServerStatusManager.java

@ikhoon ikhoon left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 👍

@jrhee17 jrhee17 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

👍 👍

@minwoox
minwoox merged commit e939b05 into line:main Jul 13, 2026
12 of 13 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants