Skip to content

Conversation

@hui-cha
Copy link
Collaborator

@hui-cha hui-cha commented Sep 23, 2025

修复下这个问题

#372 (comment)

Summary by CodeRabbit

  • Refactor

    • Improved internal handler reuse to avoid redundant recomputation; preserves behavior and has no user-facing impact.
  • Style

    • Reorganized import ordering for consistency and readability.

@coderabbitai
Copy link

coderabbitai bot commented Sep 23, 2025

Walkthrough

Reused previously computed customSessionServerHandlers when registering OpenSession to avoid a second invocation; changed customSessionServerHandlers() to return a new ArrayList<>() instead of Collections.emptyList(); imports reordered. No public APIs changed.

Changes

Cohort / File(s) Summary
Meta server bootstrap tweaks
server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java
Reordered imports; customSessionServerHandlers() now returns new ArrayList<>() (concrete mutable list) and the OpenSession register path reuses the previously computed handlers instead of invoking customSessionServerHandlers() twice.

Sequence Diagram(s)

sequenceDiagram
    participant Bootstrap as MetaServerBootstrap
    participant Handlers as customSessionServerHandlers()
    participant Registrar as OpenSessionRegistrar

    rect rgb(235,248,255)
    Note right of Bootstrap: compute handlers once
    Bootstrap->>Handlers: compute handlers (new ArrayList)
    Handlers-->>Bootstrap: handlers list
    end

    rect rgb(235,255,235)
    Note right of Bootstrap: reuse handlers when registering
    Bootstrap->>Registrar: registerOpenSession( handlers )
    Registrar-->>Bootstrap: registration result
    end
Loading

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~10 minutes

Poem

I hop through imports, neat and spry,
I build a list that won't deny.
No extra calls, no double stride,
Just one small tweak, the handlers ride.
Carrot-quiet code—contented sigh.

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title Check ✅ Passed The title succinctly and accurately describes the primary change in the PR (replacing immutable Collections.emptyList() with new ArrayList<>()), matching the PR summary and the file-level changes shown in the diff.
✨ Finishing touches
  • 📝 Generate Docstrings
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment

📜 Recent review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between bd0f500 and 0bc747d.

📒 Files selected for processing (1)
  • server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java (3 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: build

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 and usage tips.

Copy link

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java (2)

242-246: Avoid double invocation of customSessionServerHandlers().

Use the already-fetched variable to prevent recomputation and surprises if subclasses override the method with side effects.

-        if (CollectionUtils.isNotEmpty(customSessionServerHandlers)) {
-          mergedSessionServerHandlers.addAll(this.customSessionServerHandlers());
-        }
+        if (CollectionUtils.isNotEmpty(customSessionServerHandlers)) {
+          mergedSessionServerHandlers.addAll(customSessionServerHandlers);
+        }

385-387: Bug: remoteMetaServer not closed in stopServer().

remoteMetaServer.isOpen(); is a no-op; the server is never closed, causing a resource leak during shutdown.

-    if (remoteMetaServer != null && remoteMetaServer.isOpen()) {
-      remoteMetaServer.isOpen();
-    }
+    if (remoteMetaServer != null && remoteMetaServer.isOpen()) {
+      remoteMetaServer.close();
+    }
🧹 Nitpick comments (5)
server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java (5)

270-272: LGTM: return a mutable list by default to enable subclass extension.

This change prevents UnsupportedOperationException when subclasses call super.customSessionServerHandlers().add(...). Consider adding a brief Javadoc noting that subclasses may mutate and should return a new collection per call.


253-255: Prefer zero-length array in toArray().

Use new ChannelHandler[0] (JDK 11+) for simpler, typically better-performing allocation.

-                mergedSessionServerHandlers.toArray(
-                    new ChannelHandler[mergedSessionServerHandlers.size()]));
+                mergedSessionServerHandlers.toArray(new ChannelHandler[0]));

281-283: Apply the same toArray() simplification here.

-                dataServerHandlers.toArray(new ChannelHandler[dataServerHandlers.size()]));
+                dataServerHandlers.toArray(new ChannelHandler[0]));

303-305: Apply the same toArray() simplification here.

-                metaServerHandlers.toArray(new ChannelHandler[metaServerHandlers.size()]));
+                metaServerHandlers.toArray(new ChannelHandler[0]));

341-344: Apply the same toArray() simplification here.

-                remoteMetaServerHandlers.toArray(
-                    new ChannelHandler[remoteMetaServerHandlers.size()]));
+                remoteMetaServerHandlers.toArray(new ChannelHandler[0]));
📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 96f501b and bd0f500.

📒 Files selected for processing (1)
  • server/server/meta/src/main/java/com/alipay/sofa/registry/server/meta/bootstrap/MetaServerBootstrap.java (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: build

Comment on lines +50 to +57
import javax.annotation.Resource;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

Copy link

Choose a reason for hiding this comment

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

🧹 Nitpick

Avoid wildcard import; align import order with project Checkstyle.

Replace java.util.* with explicit imports and keep import groups ordered consistently to prevent future CI/lint churn.

-import javax.annotation.Resource;
-import javax.ws.rs.Path;
-import javax.ws.rs.ext.Provider;
-import java.lang.annotation.Annotation;
-import java.util.*;
-import java.util.concurrent.TimeUnit;
-import java.util.concurrent.atomic.AtomicBoolean;
+import javax.annotation.Resource;
+import javax.ws.rs.Path;
+import javax.ws.rs.ext.Provider;
+import java.lang.annotation.Annotation;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.Date;
+import java.util.List;
+import java.util.Map;
+import java.util.concurrent.TimeUnit;
+import java.util.concurrent.atomic.AtomicBoolean;
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
import javax.annotation.Resource;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.util.*;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;
import javax.annotation.Resource;
import javax.ws.rs.Path;
import javax.ws.rs.ext.Provider;
import java.lang.annotation.Annotation;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean;

@hui-cha hui-cha force-pushed the feature/replace_emptylist branch from bd0f500 to 0bc747d Compare September 23, 2025 03:55
@huanglongchao huanglongchao merged commit e936b91 into sofastack:master Sep 23, 2025
5 checks passed
@hui-cha hui-cha deleted the feature/replace_emptylist branch October 14, 2025 11:13
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.

2 participants