Skip to content

Conversation

@EvenLjj
Copy link
Collaborator

@EvenLjj EvenLjj commented Nov 12, 2025

fix biz exception cast issue

Summary by CodeRabbit

  • Bug Fixes
    • Enhanced error handling in the streaming service with improved type safety checks to prevent casting failures and ensure more robust request processing.

@sofastack-cla sofastack-cla bot added bug Something isn't working cla:yes CLA is ok size/XS labels Nov 12, 2025
@coderabbitai
Copy link
Contributor

coderabbitai bot commented Nov 12, 2025

Walkthrough

A defensive type-checking pattern was introduced in genericBiStream method. The app response object is now assigned to a local variable, validated for exceptions before casting, and thrown if an exception is detected rather than being directly cast.

Changes

Cohort / File(s) Change Summary
Exception handling in stream response
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/server/triple/GenericServiceImpl.java
Added explicit exception check and safe casting: app response is now extracted to a local variable, validated for Exception type, thrown if an exception, otherwise safely cast to SofaStreamObserver

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

  • Single-file change with localized scope
  • Straightforward defensive programming pattern (null/exception check before casting)
  • No signature changes or control flow alterations

Poem

🐰 A bunny hops through code so keen,
With safety checks now in between,
Before the cast, we pause to see,
If exceptions lurk where casts should be!
No crashes now, just peace of mind—
Better guards for types we bind! 🎯

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title 'fix biz exception cast issue' directly reflects the main change: handling an exception casting problem in genericBiStream by introducing explicit type checking and safe casting of appResponse.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fix/biz_exception_cast_issue

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 1

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/server/triple/GenericServiceImpl.java (1)

192-218: Call responseObserver.onError() instead of throwing exception in the catch block.

For server streaming, exceptions must be propagated via the StreamObserver callback, not thrown. When an exception occurs during invoker.invoke(), the current code throws SofaRpcRuntimeException, but this will not reach the client through the gRPC stream. Instead, call responseObserver.onError() to properly close the stream and notify the client.

} catch (Exception e) {
    LOGGER.error("Invoke " + methodName + " error:", e);
    responseObserver.onError(TripleExceptionUtils.asStatusRuntimeException(e));
}

This matches the error handling pattern in ResponseSerializeSofaStreamObserver.onError().

📜 Review details

Configuration used: CodeRabbit UI

Review profile: CHILL

Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between a073684 and 65fb204.

📒 Files selected for processing (1)
  • remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/server/triple/GenericServiceImpl.java (1 hunks)
🧰 Additional context used
🧠 Learnings (2)
📚 Learning: 2025-05-08T06:59:23.963Z
Learnt from: EvenLjj
Repo: sofastack/sofa-rpc PR: 1488
File: remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/interceptor/ServerReqHeaderInterceptor.java:105-120
Timestamp: 2025-05-08T06:59:23.963Z
Learning: In SOFA RPC, TripleTracerAdapter.serverReceived() sets the invocation type on the SofaRequest based on the gRPC method type (CLIENT_STREAMING, SERVER_STREAMING, BIDI_STREAMING), but the SofaRequest.isAsync() method does not directly recognize these streaming types as asynchronous. According to EvenLjj, some modification in TripleTracerAdapter.serverReceived makes sofaRequest.isAsync() return true for streaming requests.

Applied to files:

  • remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/server/triple/GenericServiceImpl.java
📚 Learning: 2025-05-08T06:34:38.670Z
Learnt from: EvenLjj
Repo: sofastack/sofa-rpc PR: 1488
File: remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/tracer/sofatracer/TripleTracerAdapter.java:290-303
Timestamp: 2025-05-08T06:34:38.670Z
Learning: In SOFA-RPC's Triple protocol adapter, the server detects invocation type (streaming/sync) from gRPC method descriptors but intentionally doesn't propagate this to request properties or headers. This is by design to maintain compatibility with clients of different versions, as the server should rely on client-provided values rather than overriding them.

Applied to files:

  • remoting/remoting-triple/src/main/java/com/alipay/sofa/rpc/server/triple/GenericServiceImpl.java
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (2)
  • GitHub Check: build
  • GitHub Check: sca

@EvenLjj EvenLjj merged commit 3b89ae3 into master Nov 13, 2025
5 of 8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working cla:yes CLA is ok size/XS

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants