Skip to content

fix(proxy): guard null context in telemetry handleGrpcCancel - #11141

Open
zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/grpc-cancel-null-context
Open

zjncs wants to merge 1 commit into
apache:developfrom
zjncs:fix/grpc-cancel-null-context

Conversation

@zjncs

@zjncs zjncs commented Sep 11, 2026

Copy link
Copy Markdown

Motivation

The telemetry stream observer keeps proxyCtx = null until the first onNext delivers a context. A client that opens the telemetry stream and then cancels (or drops the connection) without sending a single TelemetryCommand made onError call handleGrpcCancel with a null context, which threw a NullPointerException in ctx.getClientID() and masked the intended cancel handling.

Modifications

Return early when the context is absent; there is no client id to clean up in that case.

Verification

Fail-before (new test, run against the unpatched code):

ClientActivityTest#testTelemetryOnErrorBeforeAnyMessage
java.lang.NullPointerException: Cannot invoke "org.apache.rocketmq.proxy.common.ProxyContext.getClientID()" because "ctx" is null
  ClientActivityTest.testTelemetryOnErrorBeforeAnyMessage:439

Pass-after:

Tests run: 16, Failures: 0, Errors: 0, Skipped: 0 -- ClientActivityTest

The telemetry stream observer keeps proxyCtx = null until the first
onNext delivers a context. A client that opens the telemetry stream and
then cancels (or drops the connection) without sending a single
TelemetryCommand made onError call handleGrpcCancel with a null
context, which threw a NullPointerException in ctx.getClientID() and
masked the intended cancel handling.

Return early when the context is absent; there is no client id to
clean up in that case.
Copilot AI lite review requested due to automatic review settings September 11, 2026 07:12

Copilot AI left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Copilot was unable to review this pull request because the user who requested the review has reached their quota limit.

@RockteMQ-AI RockteMQ-AI 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.

Summary

Adds a null check for ctx in handleGrpcCancel to prevent NPE when the gRPC context is already cleared. Test verifies no exception is thrown.

LGTM — simple defensive null guard.


Automated review by github-manager-bot

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