Skip to content

Validate JSON object types in Consul responses - #3584

Merged
chenBright merged 1 commit into
apache:masterfrom
wasphin:fix-consul-response-types
Oct 6, 2026
Merged

chenBright merged 1 commit into
apache:masterfrom
wasphin:fix-consul-response-types

Conversation

@wasphin

@wasphin wasphin commented Oct 6, 2026

Copy link
Copy Markdown
Member

What problem does this PR solve?

Issue Number: N/A

Problem Summary:
The Consul naming service assumes that every response array entry and its
Service field are JSON objects before accessing their members. Responses
containing other JSON value types are not handled correctly.

What is changed and the side effects?

Changed:

  • Check both values with IsObject() before accessing object members and
    skip invalid entries using the existing error-handling policy.
  • Add HTTP client/server regression coverage for non-object values at both
    boundaries, mixed valid and invalid entries, and stale result clearing.
    The test server uses an automatically assigned port.

Side effects:

  • Performance effects: adds two type checks per valid service entry.
  • Breaking backward compatibility: none for valid Consul responses. Mixed
    responses retain valid services; responses with only invalid entries are
    rejected.

Check List:

Check that each node and its Service value are JSON objects before using
object accessors. Skip invalid entries while retaining valid services and
reject responses containing only invalid entries.

Add HTTP client/server regression coverage for non-object values at both
boundaries, mixed valid and invalid entries, and stale result clearing.

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

Copilot review overview

🟢 Approval recommended

The validation is correct, preserves existing behavior, and has focused regression coverage.

Review effort: Balanced
Findings: None

What changed in this PR

Adds robust JSON type validation to Consul service discovery.

Changes:

  • Skips non-object response entries and Service values.
  • Adds regression tests for invalid, mixed, and stale responses.
File Description
src/​brpc/​policy/​consul_naming_service.cpp Validates JSON objects before member access.
test/​brpc_naming_service_unittest.cpp Covers malformed Consul response values.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

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

Copilot review overview

🟢 Approval recommended

The validation is correct, preserves existing behavior, and has comprehensive regression coverage.

Review effort: Balanced
Findings: None

@chenBright chenBright 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.

LGTM

@chenBright
chenBright merged commit b13bbce into apache:master Oct 6, 2026
25 checks passed
@wasphin
wasphin deleted the fix-consul-response-types branch October 7, 2026 03:57
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