Skip to content

fix(bigtable): remove dead SessionList.inUseSessions and clear PendingVRpc references - #15037

Closed
mutianf wants to merge 1 commit into
mainfrom
fix-session-list-pending-vrpc-cleanup
Closed

mutianf wants to merge 1 commit into
mainfrom
fix-session-list-pending-vrpc-cleanup

Conversation

@mutianf

@mutianf mutianf commented Nov 16, 2026 •

Copy link
Copy Markdown
Contributor

Part 1 of 3 for b/584671437.

What changed

  • Remove unused SessionList.inUseSessions set.
  • Clear PendingVRpc references (req, listener, deadlineTimeout) once drained, cancelled, or rejected.

@mutianf
mutianf requested review from a team as code owners November 16, 2026 16:59
@mutianf
mutianf added this pull request to stack #15040 November 16, 2026 16:59

@gemini-code-assist gemini-code-assist Bot 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.

Code Review

This pull request removes the unused inUseSessions set from SessionList and cleans up references (req, listener, deadlineTimeout) in SessionPoolImpl upon cancellation or draining to prevent memory leaks. It also fixes a precondition check and marks deadlineTimeout as volatile. However, a critical issue was identified in SessionPoolImpl: using cancelWithResult in the early-fail paths of start() will trigger a NullPointerException because the instance field this.ctx is not yet initialized at that point. It is recommended to revert those early-fail paths to use the local parameters directly.

Comment on lines +943 to 959
cancelWithResult(result);
return;
}
try {
if (SessionPoolImpl.this.poolState != PoolState.STARTED) {
VRpcResult result =
VRpcResult.createUncommitedError(
Status.UNAVAILABLE.withCause(new IllegalStateException("SessionPool is closed")));
ctx.getExecutor().execute(() -> listener.onClose(result));
cancelWithResult(result);
return;
}
if (poolSizer.isDisabled()) {
VRpcResult result =
VRpcResult.createRejectedError(
Status.UNAVAILABLE.withDescription("SessionPool configuration disabled"));
ctx.getExecutor()
.execute(
() -> {
if (isCancelled) return;
isCancelled = true;
listener.onClose(result);
});
cancelWithResult(result);
return;

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.

high

Using cancelWithResult(result) for early-fail paths (such as when the pool is wedged, closed, or disabled) introduces a risk of NullPointerException if this.ctx has not been assigned yet.

Furthermore, because these early-fail paths execute before the PendingVRpc is committed to queueing, the PendingVRpc instance is never stored in the pool and is immediately eligible for garbage collection. Therefore, there is no risk of a memory leak, and clearing req and listener references is unnecessary.

It is safer and more efficient to revert to using the parameters ctx and listener directly for these early-fail paths, rather than calling cancelWithResult(result) which accesses and modifies instance fields on a potentially uninitialized or throwaway object.

        ctx.getExecutor()
            .execute(
                () -> {
                  if (isCancelled) return;
                  isCancelled = true;
                  listener.onClose(result);
                });
        return;
      }
      try {
        if (SessionPoolImpl.this.poolState != PoolState.STARTED) {
          VRpcResult result =
              VRpcResult.createUncommitedError(
                  Status.UNAVAILABLE.withCause(new IllegalStateException("SessionPool is closed")));
          ctx.getExecutor().execute(() -> listener.onClose(result));
          return;
        }
        if (poolSizer.isDisabled()) {
          VRpcResult result =
              VRpcResult.createRejectedError(
                  Status.UNAVAILABLE.withDescription("SessionPool configuration disabled"));
          ctx.getExecutor()
              .execute(
                  () -> {
                    if (isCancelled) return;
                    isCancelled = true;
                    listener.onClose(result);
                  });
          return;
        }

@mutianf
mutianf force-pushed the fix-session-list-pending-vrpc-cleanup branch from ff88244 to 5b4695e Compare November 16, 2026 20:27
@mutianf
mutianf removed this pull request from stack #15040 November 16, 2026 20:28
@mutianf
mutianf changed the base branch from fix-pool-sizer-max-capacity to main November 16, 2026 20:29
@mutianf
mutianf added this pull request to stack #15042 November 16, 2026 20:29
@mutianf mutianf closed this Nov 16, 2026
@mutianf
mutianf removed this pull request from stack #15042 November 16, 2026 21:05
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