incubator-hugegraph icon indicating copy to clipboard operation
incubator-hugegraph copied to clipboard

[Bug] describe the main problem

Open Noctis-lzy opened this issue 3 months ago • 2 comments

Bug Type (问题类型)

None

Before submit

  • [x] 我已经确认现有的 Issues 与 FAQ 中没有相同 / 重复问题 (I have confirmed and searched that there are no similar problems in the historical issue and documents)

Environment (环境信息)

HugeGraph 1.7.0(Apache Release,2025-11-16 发布,含 PR #2961 之前的代码) 3 节点 PD(raft 8610 / gRPC 8686 / REST 8620)+ 3 节点 store,CentOS 7.8,JDK 11

Expected & Actual behavior (期望与实际表现)

Expected(期望表现):

1-PD 集群整体重启后,Raft 重新选主、leader 可能落在任意节点——这本身是正常行为;无论 leader 是哪台,follower 都应能将请求转发(redirect)到新 leader,集群保持高可用; 2-/v1/members 应正确显示各成员 Up、grpcUrl 已填充,pdLeader 指向当前 leader; 3-RaftEngine.getMembers() 所依赖的成员查询 RPC 应能正常工作(至少查询本机 localhost 不应失败)。

Actual(实际表现):

1-(同 #3001)重启后 follower 转发瘫痪:整集群重启且 leader 换节点后,follower PD 持续报错,集群不可用: [WARN] o.a.h.p.s.ServiceGrpc - redirect to leader with error: 冒号后为空(NPE 的 getMessage() 为 null)。根因是 1.7.0 的 RaftEngine.getLeaderGrpcAddress() 中 .get() 无超时、且对 null 响应直接调 .getGrpcAddress() 产生 NPE(master 已由 #2961 修复,但截至 2026-08 尚无包含该修复的 release)。

2-(本 issue 新增)底层成员查询 bolt RPC 对所有 peer 全部失败,包括 localhost:手工将 #2961 回移植到 1.7.0 后,follower 转发通过降级地址恢复、集群功能正常,但每次调用 /v1/members,leader 日志固定打出 3 对错误(对三个 raft peer 各一次,含 leader 查询自己 10.143.208.94:8610): 2026-08-26 21:27:40 [ERROR] o.a.h.p.r.RaftRpcClient - failed to call rpc to 10.143.208.92:8610. null 2026-08-26 21:27:40 [ERROR] o.a.h.p.r.RaftEngine - failed to getGrpcAddress of 10.143.208.92:8610 localhost 也 NPE 说明并非网络/防火墙问题,而是 RaftRpcClient.getGrpcAddress()(自定义 GetMemberRequest bolt 调用)本身的问题。#2961 只对 getLeaderGrpcAddress 一个调用方做了容错,未修复该 RPC 本身。

3-受影响的唯一未保护调用方 RaftEngine.getMembers():RPC 全败 → 所有成员被标 Offline、grpcUrl/restUrl/dataPath 全空 → /v1/members 返回 stateCountMap:{"Offline":3}、pdLeader:null,而实际 raft 集群状态为 Cluster_OK、选举/快照/日志复制均正常——监控视图与集群真实状态完全背离。

影响面与当前规避:

1-功能层不受影响(store 注册/心跳不调用该 RPC;PDClient 找 leader 用的是 GetMembersResponse.leader 字段,由 leader 本地构造、数据正确); 2-但 #2961 的降级地址 = leader raft IP + 本机 grpc.port,要求所有 PD 节点 grpc 端口一致,且 /v1/members 的成员列表/pdLeader 不可信; 3-建议对 getMembers() 增加与 #2961 同等的容错,并排查 GetMemberRequest bolt RPC 本身 NPE 的根因(该错误日志 failed to call rpc to {}. {} 只打印 getMessage() 不打印堆栈,NPE 场景下无栈可查,建议补充异常对象输出)。

Vertex/Edge example (问题点 / 边数据举例)

null

Schema [VertexLabel, EdgeLabel, IndexLabel] (元数据结构)


Visual summary

PD member RPC and release gap

Noctis-lzy avatar Aug 26 '26 13:08 Noctis-lzy

Hi @Noctis-lzy! I'm Dosu and I'm helping the HugeGraph team.

Your root cause analysis is accurate across all three problems. I've verified it against the current master codebase.

Problem 1: getMembers() has no timeout or null-safety on the bolt RPC

In RaftEngine.getMembers(), the call to future.get() at line 334 is unbounded — no timeout is applied. By contrast, getLeaderGrpcAddress() was hardened in PR #2961 with future.get(config.getRpcTimeout(), TimeUnit.MILLISECONDS) plus fallback handling [1], but getMembers() was not given the same treatment. Additionally, future.isCompletedExceptionally() is checked at line 328 before future.get() at line 334, creating a TOCTOU race — a future that completes exceptionally after the check but before get() will propagate as an unhandled ExecutionException, marking the node Offline.

Problem 2: The truncated failed to call rpc to {}. {} log

In RaftRpcClient.internalCallAsyncWithRpc(), the catch block logs:

log.error("failed to call rpc to {}. {}", endpoint, t.getMessage());

When the exception is an NPE, t.getMessage() returns null, producing the truncated log you observed. The exception object (including stack trace) is never logged. Changing this to log.error("failed to call rpc to {}", endpoint, t) would cause SLF4J to append the full stack automatically.

Problem 3: Why the bolt RPC fails for all peers including localhost

The IpAuthHandler whitelist configured in createRaftRpcServer() is populated from the peer IPs in the Raft configuration. A plausible explanation for the localhost failure is that the Bolt client's source IP is 127.0.0.1 (loopback) while the whitelist only contains the real NIC IP (e.g., 10.143.208.94), causing IpAuthHandler to reject the connection. This would produce an exception that, via FutureClosureAdapter.failure(), completes the future exceptionally — but since the error message is null for an NPE, the log gives no useful context. That said, I wasn't able to fully confirm this theory from the code alone; it may warrant further investigation.

Suggested fixes for getMembers():

  1. Add timeout to future.get() — mirror the getLeaderGrpcAddress() pattern: future.get(config.getRpcTimeout(), TimeUnit.MILLISECONDS) with a catch (TimeoutException).
  2. Fix the TOCTOU race on future.isCompletedExceptionally() — check after get() in the catch block rather than before.
  3. Self-query shortcut — when peerId equals the local node's endpoint, skip the RPC and return getLocalMember() directly. This makes the leader-querying-itself case reliable regardless of whitelist or network config.
  4. Improve logging — change the log.error in RaftRpcClient [2] to pass the throwable object directly so full stack traces are captured on NPE.

The self-query shortcut (point 3) is the most targeted fix for the "leader queries itself and fails" scenario. For a 1.7.0 backport, applying the timeout-bounded get() and the local-node shortcut to getMembers() should resolve /v1/members incorrectly showing all Offline and pdLeader: null.

To reply, just mention @dosu.


Docs are dead. Just use Dosu.

Leave Feedback Ask Dosu about hugegraph Share Dosu with your team

dosubot[bot] avatar Aug 26 '26 13:08 dosubot[bot]

The cause of problems 2 and 3, and of problem 1 as well

All three symptoms are the same exception. In 1.7.0 RaftRpcClient.init() calls rpcClient.init(null), so jraft's BoltRpcClient.opts is null, and internalCallAsyncWithRpc() passes invokeCtx = null. In jraft 1.3.13 BoltRpcClient.getBoltInvokeCtx(null) evaluates this.opts.isEnableRpcChecksum() and throws a NullPointerException with no message, synchronously, before anything is sent. It is caught by the catch (Throwable t) that logs only t.getMessage(), hence failed to call rpc to X. null. Every GetMemberRequest therefore fails, for every peer including the node itself, which is why localhost "fails" too. It is not the IP whitelist: IpAuthHandler only appeared in May 2026, 1.7.0 does not have it.

Stack trace from the official apache-hugegraph-incubating-1.7.0, follower, GET /v1/members:

MemberAPI.getMembers(MemberAPI.java:77)
  RaftEngine.getLeaderGrpcAddress(RaftEngine.java:242)
    RaftRpcClient.getGrpcAddress(RaftRpcClient.java:56)
      RaftRpcClient.internalCallAsyncWithRpc(RaftRpcClient.java:80)
        BoltRpcClient.invokeAsync(BoltRpcClient.java:113)
          BoltRpcClient.getBoltInvokeCtx(BoltRpcClient.java:135)   <- NullPointerException

The same RPC serves getLeaderGrpcAddress() (problem 1) and getMembers() (problem 3), so on 1.7.0 a follower can never redirect to the leader and /v1/members never has correct data.

Master fixed it by accident

Commit b9a3dd9 ("chore(ci): enable hugegraph-struct tests", #3038) changed invokeCtx = null to new InvokeContext(), which bypasses the this.opts branch. The same commit carries the getLeaderGrpcAddress() hardening known as #2961. rpcClient.init(null) stayed, so opts is still null and any future path with an empty context returns to this NPE. Nobody has linked that commit to this issue.

Reproduction on a lab: 1.7.0 vs master, 3 PD nodes

Three VMs, one raft group, the same script for both builds (cluster/pd3.sh): fresh start, check every node, stop all, restart with the previous leader last, check again.

step official 1.7.0 master 60c8803
fresh start, /v1/members on the leader pdLeader: null, 3 × Offline, grpcUrl: "" leader 235, 3 × Up, every grpcUrl filled
fresh start, /v1/members on a follower HTTP 500, ExecutionException: NullPointerException from getLeaderGrpcAddress same answer as on the leader (redirected)
restart all, leader last the leader moved, behaviour unchanged: followers 500, leader 3 × Offline leader 235 → 236, all three nodes answer, 3 × Up, one transient failed to call rpc on the node that came up first
a store pointing at a follower does not register (Exception in storage registration ... pd=192.168.80.235:8686) n/a
single node, query to itself ~9 400 lines of failed to call rpc to 127.0.0.1:8610. null within 10 s of start none, /v1/members Up with grpcUrl

A stronger conclusion than the issue text: on 1.7.0 a follower is broken from the first start, not only after a leader change. The restart merely exposes it, because until then every client happened to hit the leader. It also explains why a #2961 backport always takes the fallback path (leader address from the local gRPC port): the real RPC has never worked on 1.7.0, not once.

What I would suggest

  • A 1.7.x backport is two lines: new InvokeContext() instead of null in internalCallAsyncWithRpc(), and, properly, rpcClient.init(rpcOptions) instead of init(null) so that opts is not null.
  • On master the same init(rpcOptions), plus log.error("failed to call rpc to {}", endpoint, t) so that the next message-less NPE does not cost anyone a week.
  • The closed #3195 treated the symptom (a static address map); with this cause the map is not needed.

Script, the logs of both cycles and the stack trace excerpt: results/issue-3172/. If anyone wants, I can test the backport on the same setup.

SebastianGruza avatar Sep 12 '26 17:09 SebastianGruza