Skip to content

Commit

Permalink
RATIS-2225. RaftClientRequest leak in RaftServerImpl. (#1198)
Browse files Browse the repository at this point in the history
  • Loading branch information
szetszwo authored Dec 23, 2024
1 parent de2fec6 commit 0514e09
Showing 1 changed file with 15 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,15 @@ synchronized void changeToLeader() {

@Override
public Collection<CommitInfoProto> getCommitInfos() {
try {
return getCommitInfosImpl();
} catch (Throwable t) {
LOG.warn("{} Failed to getCommitInfos", getMemberId(), t);
return Collections.emptyList();
}
}

private Collection<CommitInfoProto> getCommitInfosImpl() {
final List<CommitInfoProto> infos = new ArrayList<>();
// add the commit info of this server
final long commitIndex = updateCommitInfoCache();
Expand Down Expand Up @@ -922,17 +931,10 @@ CompletableFuture<RaftClientReply> executeSubmitClientRequestAsync(
public CompletableFuture<RaftClientReply> submitClientRequestAsync(
ReferenceCountedObject<RaftClientRequest> requestRef) {
final RaftClientRequest request = requestRef.retain();
LOG.debug("{}: receive client request({})", getMemberId(), request);

try {
LOG.debug("{}: receive client request({})", getMemberId(), request);
assertLifeCycleState(LifeCycle.States.RUNNING);
} catch (ServerNotReadyException e) {
final RaftClientReply reply = newExceptionReply(request, e);
requestRef.release();
return CompletableFuture.completedFuture(reply);
}

try {
RaftClientRequest.Type type = request.getType();
final Timekeeper timer = raftServerMetrics.getClientRequestTimer(type);
final Optional<Timekeeper.Context> timerContext = Optional.ofNullable(timer).map(Timekeeper::time);
Expand All @@ -942,6 +944,11 @@ public CompletableFuture<RaftClientReply> submitClientRequestAsync(
raftServerMetrics.incFailedRequestCount(type);
}
});
} catch (RaftException e) {
return CompletableFuture.completedFuture(newExceptionReply(request, e));
} catch (Throwable t) {
LOG.error("{} Failed to submitClientRequestAsync for {}", getMemberId(), request, t);
return CompletableFuture.completedFuture(newExceptionReply(request, new RaftException(t)));
} finally {
requestRef.release();
}
Expand Down

0 comments on commit 0514e09

Please sign in to comment.