-
-
Notifications
You must be signed in to change notification settings - Fork 12
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Propagate response headers with grpc error metadata #32
base: 3.x
Are you sure you want to change the base?
Conversation
WalkthroughThe pull request introduces several changes across multiple files. It adds a new Changes
Poem
Tip Announcements
Recent review detailsConfiguration used: CodeRabbit UI Files selected for processing (1)
Files skipped from review as they are similar to previous changes (1)
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (Invoked using PR comments)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Outside diff range, codebase verification and nitpick comments (2)
src/Internal/CallContext.php (1)
30-38
: Add error handling inJson::decode
method to manage JSON parsing errors.The
Json::decode
method insrc/Internal/Json.php
usesjson_decode
but lacks error handling for potential parsing errors. Consider implementing checks usingjson_last_error()
to ensure robust handling of malformed JSON inputs.
- File:
src/Internal/Json.php
- Method:
Json::decode
Analysis chain
Method
decode
is effectively implemented but ensure robust error handling.The method effectively decodes the JSON payload and initializes a
CallContext
instance. Ensure thatJson::decode
properly handles JSON parsing errors. IfJson::decode
does not handle exceptions, consider adding error handling in this method to manage malformed JSON inputs gracefully.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify error handling in Json::decode method. # Test: Search for the Json::decode implementation. Expect: Exception handling for JSON errors. ast-grep --lang php --pattern $'class Json { $$$ decode($_, $_) { $$$ } $$$ }'Length of output: 93
Script:
#!/bin/bash # Description: Search for the decode method in any Json class to verify its existence and error handling. # Test: Use ripgrep to find the decode method in any Json class. rg 'class Json' -A 10 | rg 'function decode'Length of output: 46
Script:
#!/bin/bash # Description: Search for any decode method in the codebase that might handle JSON parsing. # Test: Use ripgrep to find any decode method that might be responsible for JSON parsing. rg 'function decode' -A 5Length of output: 658
src/Server.php (1)
Line range hint
123-161
: Enhancements and potential issues in error response handling.The
workerGrpcError
method has been significantly modified to include a nullableContextInterface
and to utilize theResponseHeaders
within the error handling process. This is a crucial part of the PR's objective to propagate response headers with gRPC error metadata.Key observations:
- Nullable Context: The method now accepts a nullable
ContextInterface
, which allows for more flexible error handling. However, this also introduces the risk of null dereferencing when accessing methods oncontext
. It's important to ensure that all calls tocontext
methods are safe and handle the possibility of a null context.- Response Header Propagation: The method attempts to merge response headers with error details, which aligns with the PR's goals. However, the implementation assumes that
responseHeaders
is always initialized whencontext
is not null. This might not always be the case, and could lead to issues ifresponseHeaders
is null.Consider adding null checks and more defensive programming to ensure that the headers and error details are always correctly handled.
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- composer.json (1 hunks)
- src/Internal/CallContext.php (1 hunks)
- src/ResponseHeaders.php (1 hunks)
- src/Server.php (6 hunks)
Additional comments not posted (2)
src/Internal/CallContext.php (1)
20-24
: Constructor implementation is clean and modern.The use of PHP 8 promoted properties in the constructor enhances readability and maintainability. The type declarations for parameters ensure that the method can only be called with the correct types.
composer.json (1)
75-79
:branch-alias
addition is correctly implemented.The addition of the
branch-alias
section is correctly formatted and follows best practices for Composer configuration. This change will facilitate easier dependency management and versioning during development.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (1)
- src/Server.php (6 hunks)
Additional comments not posted (4)
src/Server.php (4)
136-139
: Proper handling of response headers in gRPC responses.The modifications to the
workerSend
method ensure that response headers are correctly packaged and sent with gRPC responses. This change is essential for maintaining the integrity of the communication protocol and ensuring that all necessary headers are included in responses.Verify that headers are correctly handled in all response scenarios to ensure that no headers are missed or incorrectly formatted.
Run the following script to verify the correct handling of headers in responses:
Verification successful
Proper handling of response headers in gRPC responses confirmed.
The
workerSend
method is used appropriately to ensure that headers are included in both successful and error responses. The headers are encoded as JSON, indicating they are structured correctly. No issues were found with the handling of headers.
- Usage of
workerSend
insrc/Server.php
confirms proper handling of headers.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the correct handling of headers in gRPC responses. # Test: Search for the usage of `workerSend` method. Expect: Proper handling and inclusion of headers in responses. rg --type php -A 5 $'workerSend'Length of output: 1051
70-101
: Streamlined gRPC request and response handling.The modifications to the
serve
method enhance clarity and efficiency by usingCallContext
for managing request headers and context. The direct invocation of service methods and the inclusion of response headers in error responses align well with the PR objectives.Ensure that the integration of
CallContext
with other components is thoroughly tested, especially in error scenarios, to confirm that all necessary headers are correctly propagated.Run the following script to verify the integration of
CallContext
:
128-131
: Enhanced flexibility in error handling.The addition of a nullable
ContextInterface
parameter to theworkerError
method allows for more nuanced error handling, supporting the propagation of error context. This change is a positive step towards improving error diagnostics and response management.Verify that the new parameter is used effectively across all error handling scenarios to ensure that error contexts are properly utilized.
Run the following script to verify the usage of the new
ContextInterface
parameter:
Line range hint
141-157
: Correct encoding of gRPC error statuses.The modifications to the
createGrpcError
method ensure that gRPC error statuses are correctly formatted and encoded. This change is essential for maintaining the integrity of error communication and ensuring that all necessary details are included in error responses.Verify that error statuses are correctly encoded in all error scenarios to ensure that no details are missed or incorrectly formatted.
Run the following script to verify the correct encoding of gRPC error statuses:
…th grpc error metadata
e97fc6f
to
e041c42
Compare
25b43a5
to
af71e16
Compare
@rauanmayemir Feature was released from the RR side. |
This change propagates response headers as part of grpc error response. This is helpful when your server needs to send certain headers (like
X-Correlation-Id
, etc) even in case of Exception.Update: this change also introduces
ResponseTrailers
which could be used alongsideResponseHeaders
. It is expected to send data like this:And if it's a successful response, then binary payload headers part will also accordingly change from this:
to this:
ref: roadrunner-server/roadrunner#2006
@rustatian:
Note, this PR should be synced with RR 2024.3 release.
Summary by CodeRabbit
Summary by CodeRabbit
New Features
CallContext
class for structured representation of gRPC call contexts, enhancing organization and handling of service calls.getHeaders()
method to theResponseHeaders
class for improved access to internal headers.ResponseTrailers
class for managing and manipulating trailer headers in gRPC responses.Improvements
tick
method and utilizing the newCallContext
for better efficiency.workerError
method by allowing a nullable context parameter.Configuration Updates
composer.json
to include abranch-alias
for flexible dependency management.