Skip to content

drpcmux: fix server interceptor selection logic #13

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

Merged

Conversation

shubhamdhama
Copy link

@shubhamdhama shubhamdhama commented Jul 20, 2025

This commit fixes a bug in the interceptor selection logic in HandleRPC.
The issue was that we were passing a stream to the receiver for the case
where the input is unitary and the output is a stream.

The fix is to receive the message from the stream within the final receiver
after going through the stream interceptor pipeline. This also means we no
longer receive the message outside the switch statement.

Copy link

@Copilot 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

This PR fixes a bug in the interceptor selection logic where the wrong criteria was being used to determine which interceptor type to apply. The fix changes the logic to select interceptors based on input type rather than output type, and updates function signatures to remove unnecessary context parameters from stream handlers.

  • Changes interceptor selection from using data.unitary (output type) to data.in1 != streamType (input type)
  • Removes redundant context parameters from stream handler signatures since context is available through stream.Context()
  • Updates parameter names for better clarity (e.g., in to req)

Reviewed Changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
drpcmux/interceptor.go Updates function signatures to remove context parameters from stream handlers and improves parameter naming
drpcmux/handle_rpc.go Fixes the core bug by changing interceptor selection logic from output-based to input-based criteria

} else if data.in1 == streamType && m.streamInterceptor != nil {
out, err = m.streamInterceptor(stream, rpc,
func(st drpc.Stream) (interface{}, error) {
return data.receiver(data.srv, st.Context(), st, stream)
Copy link
Preview

Copilot AI Jul 21, 2025

Choose a reason for hiding this comment

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

The stream parameter is being passed twice - once as 'st' (the input stream from the handler) and once as 'stream' (the original stream). This could be confusing and may indicate incorrect usage. Verify that both parameters are needed or if one should be removed.

Suggested change
return data.receiver(data.srv, st.Context(), st, stream)
return data.receiver(data.srv, st.Context(), st)

Copilot uses AI. Check for mistakes.

@shubhamdhama shubhamdhama force-pushed the fix-server-interc-selection branch from ef5c556 to e1fc085 Compare July 22, 2025 13:00
This commit fixes a bug in the interceptor selection logic in HandleRPC.
The issue was that we were passing a stream to the receiver for the case
where the input is unitary and the output is a stream.

The fix is to receive the message from the stream within the final receiver
after going through the stream interceptor pipeline. This also means we no
longer receive the message outside the switch statement.
@shubhamdhama shubhamdhama force-pushed the fix-server-interc-selection branch from e1fc085 to eb2923d Compare July 23, 2025 11:00
@cthumuluru-crdb cthumuluru-crdb self-requested a review July 30, 2025 10:28
Copy link

@cthumuluru-crdb cthumuluru-crdb left a comment

Choose a reason for hiding this comment

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

LGTM! Can you please make sure we have test coverage for all interceptor types?

@cthumuluru-crdb
Copy link

@shubhamdhama - if you don't have a PR with tests already to cover interceptors logic, please create a tracking ticket.

@shubhamdhama
Copy link
Author

@shubhamdhama - if you don't have a PR with tests already to cover interceptors logic, please create a tracking ticket.

PR #14: drpcmux: add tests for server interceptors

This PR has it covered.

@shubhamdhama shubhamdhama merged commit 7e672f3 into cockroachdb:main Jul 31, 2025
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.

2 participants