Skip to content

Conversation

@pkarumanchi9
Copy link
Contributor

Fixes NullPointerException in bulk get operations when some operations
never signal completion through callbacks. The issue was introduced in
commit e4a2a9b which optimized operation state checking by collecting
state during callbacks, but didn't handle cases where callbacks don't fire.

This fix adds a fallback mechanism that preserves the original behavior:

  • Use pre-collected state when available (maintains performance optimization)
  • Fall back to direct operation state checking when state is null
  • Ensures all operations are processed, matching pre-e4a2a9bd behavior

The root cause was that operationStates[i] could remain null if
signalSingleOpComplete() was never called for operations that timeout,
fail, or are cancelled before their completion callbacks fire.

  Fixes NullPointerException in bulk get operations when some operations
  never signal completion through callbacks. The issue was introduced in
  commit e4a2a9b which optimized operation state checking by collecting
  state during callbacks, but didn't handle cases where callbacks don't fire.

  This fix adds a fallback mechanism that preserves the original behavior:
  - Use pre-collected state when available (maintains performance optimization)
  - Fall back to direct operation state checking when state is null
  - Ensures all operations are processed, matching pre-e4a2a9bd behavior

  The root cause was that operationStates[i] could remain null if
  signalSingleOpComplete() was never called for operations that timeout,
  fail, or are cancelled before their completion callbacks fire.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

Fixes a NullPointerException in EVCacheBulkGetFuture that occurs when operations never signal completion through callbacks. The fix adds fallback logic to handle null states by checking operation status directly when the optimized pre-collected state is unavailable.

  • Adds null state checking with fallback to direct operation state inspection
  • Preserves performance optimization by using pre-collected state when available
  • Ensures all operations are processed even when callbacks don't fire

Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.

}

boolean hadTimedoutOp = false;
Operation[] opsArray = ops.toArray(new Operation[0]);
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

Converting ops to array in each method creates unnecessary overhead. Consider making opsArray a class field initialized once, or cache it to avoid repeated conversions in getSome(), handleBulkException(), and getSome() methods.

Copilot uses AI. Check for mistakes.
if (!state.completed && !allCompleted) {
MemcachedConnection.opTimedOut(state.op);
hadTimedoutOp = true;
Operation op = opsArray[i];
Copy link

Copilot AI Aug 15, 2025

Choose a reason for hiding this comment

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

The same pattern of 'if (state == null)' fallback logic is duplicated across multiple methods. Consider extracting this logic into a private helper method to reduce code duplication and improve maintainability.

Copilot uses AI. Check for mistakes.
@pkarumanchi9 pkarumanchi9 marked this pull request as ready for review August 15, 2025 17:12

if (state == null) {
// Operation never signaled completion, fall back to direct checking
if (op.getState() != OperationState.COMPLETE) {
Copy link
Contributor

@shy-1234 shy-1234 Aug 15, 2025

Choose a reason for hiding this comment

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

Isn't this the same as (the reason why) state == null? Do we ever go into line 138? (same for line 259)

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.

3 participants