Skip to content

Conversation

@eddyashton
Copy link
Member

Aiming to use the get_redirect_address_for_node helper added in #7373 for other node_frontend.h redirects, to make sure they don't try to redirect to an interface that doesn't exist on the target node.

That should be a tiny diff, but because some of the endpoints use json_adapter and others don't, it's extremely awkward and unwieldy. I may take another stab at this because the diff is so ugly, but if that fails we should merge this to get a fix in.

Copilot AI review requested due to automatic review settings October 22, 2025 12:42
@eddyashton eddyashton requested a review from a team as a code owner October 22, 2025 12:42
Copy link
Contributor

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 improves redirect handling for node RPC endpoints by ensuring redirects only target interfaces that exist on the destination node. The main change is refactoring the get_redirect_address_for_node helper to be used consistently across multiple endpoints (/node/join, /node/primary, and /node/snapshot), preventing attempts to redirect to non-existent interfaces.

Key changes:

  • Unified redirect logic using get_redirect_address_for_node across multiple endpoints
  • Changed return type from std::optional<std::string> to std::variant<std::string, JsonAdapterResponse> to support both json_adapter and non-json_adapter endpoints
  • Added test coverage to verify error handling when redirecting to interfaces that don't exist on the target node

Reviewed Changes

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

File Description
tests/infra/interfaces.py Added from_str static method to RPCInterface for creating instances from string addresses
tests/e2e_common_endpoints.py Added test case that creates a node with a unique interface and verifies proper error handling when redirecting to missing interfaces
src/snapshots/fetch.h Cleared response buffer after redirect to avoid carrying over redirect response bodies
src/node/rpc/node_frontend.h Refactored redirect logic to use centralized helper function consistently across endpoints, converted several endpoints to use json_adapter

return ccf::make_error(
HTTP_STATUS_PERMANENT_REDIRECT,
ccf::errors::NodeCannotHandleRequest,
"Redirecting to primary");
Copy link

Copilot AI Oct 22, 2025

Choose a reason for hiding this comment

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

The error message 'Redirecting to primary' is misleading in the context of the /snapshot endpoint. This message suggests redirection to the primary node, but this endpoint redirects to the current node's snapshot. Consider changing the message to something like 'Redirecting to snapshot' to accurately reflect the operation.

Suggested change
"Redirecting to primary");
"Redirecting to snapshot");

Copilot uses AI. Check for mistakes.
Comment on lines +280 to +281
// Ignore any body from redirect responses
response_body->buffer.clear();
Copy link
Member Author

Choose a reason for hiding this comment

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

Explanation: When we make a GET request, we don't know whether it's going to be a redirect or a partial body. We use the same response_body object for all calls, and it blindly pastes the body onto the end of an internal buffer. That's exactly the behaviour that we want when we're calling subsequent range requests, but we don't want to include the body of a redirect response. Previously they had no body so this wasn't a problem, now they do.

Ideally we'd be deciding how to handle the body based on the headers, but that's awkward with curl. Perhaps we should create a fresh ResponseBody per response, and glue together the ones we want at the end? That implies some extra resizing and probably a copy, so this is faster, just ugly.

@eddyashton
Copy link
Member Author

Superceded by #7395, which makes some different choices to make the diff a little tidier.

@eddyashton eddyashton closed this Oct 22, 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.

1 participant