Skip to content

server: validate store addresses on PutStore#11039

Open
bufferflies wants to merge 2 commits into
tikv:masterfrom
bufferflies:bugfix/mismatch_tikv_address
Open

server: validate store addresses on PutStore#11039
bufferflies wants to merge 2 commits into
tikv:masterfrom
bufferflies:bugfix/mismatch_tikv_address

Conversation

@bufferflies

@bufferflies bufferflies commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

What problem does this PR solve?

Issue Number: Close #11038

What is changed and how does it work?

Validate store addresses during PutStore by dialing each configured store address before persisting store metadata.

Return INVALID_VALUE when an address cannot be parsed or dialed, and keep mock addresses accepted for tests.

Check List

Tests

  • Unit test

Code changes

  • None

Side effects

  • Increased code complexity

Related changes

  • Need to cherry-pick to the release branch

Release note

Reject unreachable store addresses when registering stores through PutStore.

Summary by CodeRabbit

  • Bug Fixes
    • Store registration now checks that configured store network addresses are reachable before persisting store metadata.
    • Invalid, unreachable, or misformatted addresses now fail with a clearer validation error.
    • Mock-style addresses are still allowed.
  • Tests
    • Added unit coverage for store-address validation (reachable, unreachable, and mock-style cases).
  • Chores
    • Updated Go module dependencies (including adding a reachability probing library).

@ti-chi-bot ti-chi-bot Bot added dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. labels Jul 23, 2026
@ti-chi-bot

ti-chi-bot Bot commented Jul 23, 2026

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign siddontang for approval. For more information see the Code Review Process.
Please ensure that each of them provides their approval before proceeding.

The full list of commands accepted by this bot can be found here.

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@ti-chi-bot ti-chi-bot Bot added the size/L Denotes a PR that changes 100-499 lines, ignoring generated files. label Jul 23, 2026
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

📝 Walkthrough

Walkthrough

PutStore now validates store addresses before persisting metadata, probing configured hosts with timeout and cancellation handling while allowing mock:// addresses. Cluster tests cover reachable, unreachable, and mock address cases.

Changes

Store address validation

Layer / File(s) Summary
Address validation and PutStore integration
server/grpc_service.go, go.mod
Adds address parsing, deduplicated ICMP reachability checks, mock-address handling, and INVALID_VALUE responses before metadata persistence.
Address validation coverage
tests/server/cluster/cluster_test.go
Adds cluster coverage for reachable, unreachable, and mock store addresses.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant PutStore
  participant validateStoreAddress
  participant dialAddress
  participant StoreEndpoint
  PutStore->>validateStoreAddress: validate configured store addresses
  validateStoreAddress->>dialAddress: parse and probe each unique address
  dialAddress->>StoreEndpoint: send ICMP probe
  StoreEndpoint-->>dialAddress: probe result
  dialAddress-->>validateStoreAddress: validation result
  validateStoreAddress-->>PutStore: persist metadata or return INVALID_VALUE
Loading

Suggested reviewers: lhy1024, amoebaprotozoa

🚥 Pre-merge checks | ✅ 3 | ❌ 2

❌ Failed checks (2 warnings)

Check name Status Explanation Resolution
Linked Issues check ⚠️ Warning The issue requires rejecting unreachable TCP-dialable store addresses, but the PR validates reachability with ICMP ping instead. Use a TCP dial/check against each store address and return INVALID_VALUE when dialing fails, rather than relying on ICMP ping.
Docstring Coverage ⚠️ Warning Docstring coverage is 33.33% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly summarizes the main change: validating store addresses during PutStore.
Description check ✅ Passed The PR description includes the issue number, change summary, tests, side effects, related changes, and release note.
Out of Scope Changes check ✅ Passed The changes stay focused on PutStore address validation, tests, and supporting dependency updates.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests

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.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 3

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/grpc_service.go`:
- Around line 831-845: Update validateStoreAddress to validate the store’s
Address, StatusAddress, and PeerAddress directly in that order instead of
collecting them in a map. When dialAddress fails, return or propagate the
associated endpoint address so callers can identify the exact failing field in
the INVALID_VALUE message, while preserving the existing successful-validation
behavior.
- Around line 809-824: Update the PutStore validation flow, including
validateStoreAddress and dialAddress, to reject unsupported schemes and enforce
the trusted allowlist for 127.0.0.1 and other local-only addresses before any
TCP probe. Apply this validation consistently to metapb.Store Address,
StatusAddress, and PeerAddress, while preserving the existing mock:// handling
and only dialing approved non-mock endpoints.

In `@tests/server/cluster/cluster_test.go`:
- Around line 2242-2244: Update the deferred cleanup for listener in the test to
assert the error returned by listener.Close(), matching the existing
unreachableListener.Close() cleanup pattern and avoiding a discarded error.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: 929e3953-98ba-4dfe-88ee-adfacc026f07

📥 Commits

Reviewing files that changed from the base of the PR and between 39b6220 and 102072c.

📒 Files selected for processing (2)
  • server/grpc_service.go
  • tests/server/cluster/cluster_test.go

Comment thread server/grpc_service.go Outdated
Comment thread server/grpc_service.go
Comment thread tests/server/cluster/cluster_test.go Outdated
Signed-off-by: tongjian <1045931706@qq.com>
@bufferflies
bufferflies force-pushed the bugfix/mismatch_tikv_address branch from 102072c to de5496d Compare July 23, 2026 02:53
Comment thread server/grpc_service.go

// TiKV puts the store before listening on its store address, so PD can only
// validate the configured address by checking whether it is dialable.
if err := validateStoreAddress(ctx, store); err != nil {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

TiKV calls PutStore before its gRPC server is built and bound. This dial therefore returns connection refused, PD responds with INVALID_VALUE, and TiKV aborts before it can start listening. Please avoid requiring address reachability during PutStore, or coordinate a two-phase startup protocol.

@bufferflies
bufferflies requested a review from lhy1024 July 24, 2026 06:40
Signed-off-by: bufferflies <1045931706@qq.com>
@bufferflies
bufferflies requested a review from rleungx July 24, 2026 07:17
@ti-chi-bot

ti-chi-bot Bot commented Jul 24, 2026

Copy link
Copy Markdown
Contributor

@bufferflies: The following tests failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-unit-test-next-gen-3 d569117 link true /test pull-unit-test-next-gen-3
pull-unit-test-next-gen-2 d569117 link true /test pull-unit-test-next-gen-2
pull-unit-test-next-gen-1 d569117 link true /test pull-unit-test-next-gen-1
pull-build-next-gen d569117 link true /test pull-build-next-gen
pull-build d569117 link true /test pull-build
pull-integration-realcluster-test d569117 link true /test pull-integration-realcluster-test

Full PR test history. Your PR dashboard.

Details

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. I understand the commands that are listed here.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Actionable comments posted: 1

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@server/grpc_service.go`:
- Around line 819-850: Update server/grpc_service.go in the dialAddress
validation flow (around probing.NewPinger) to validate connectivity to the
configured host and port rather than only issuing ICMP against the stripped
host, while preserving context cancellation and error propagation. Update
tests/server/cluster/cluster_test.go at lines 2254-2260 so the live-host
negative case targets a closed store endpoint port; both sites require changes.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: defaults

Review profile: CHILL

Plan: Pro Plus

Run ID: d9908822-f7cb-4d14-9e31-0b209c4336ea

📥 Commits

Reviewing files that changed from the base of the PR and between de5496d and d569117.

⛔ Files ignored due to path filters (1)
  • go.sum is excluded by !**/*.sum
📒 Files selected for processing (3)
  • go.mod
  • server/grpc_service.go
  • tests/server/cluster/cluster_test.go

Comment thread server/grpc_service.go
Comment on lines +819 to +850
host, _, err := net.SplitHostPort(hostPort)
if err != nil {
return errors.WithStack(err)
}

pinger, err := probing.NewPinger(host)
if err != nil {
return errors.WithStack(err)
}
pinger.Count = 1
pinger.Timeout = defaultGRPCDialTimeout
pinger.SetPrivileged(false)

done := make(chan error, 1)
go func() {
done <- pinger.Run()
}()

select {
case <-ctx.Done():
pinger.Stop()
return errors.WithStack(ctx.Err())
case err := <-done:
if err != nil {
return errors.WithStack(err)
}
}

stats := pinger.Statistics()
if stats.PacketsRecv == 0 {
return errors.Errorf("no ICMP reply from %s", host)
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🗄️ Data Integrity & Integration | 🟠 Major | 🏗️ Heavy lift

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== files =="
git ls-files | rg '(^|/)grpc_service\.go$|(^|/)cluster_test\.go$'

echo "== grpc_service relevant lines =="
sed -n '760,870p' server/grpc_service.go 2>/dev/null || true

echo "== cluster test relevant lines =="
sed -n '2230,2275p' tests/server/cluster/cluster_test.go 2>/dev/null || true

echo "== ping/store validation usages =="
rg -n "SplitHostPort|NewPinger|PacketsRecv|unreachable-host|putStore|Address:" server tests -S

Repository: tikv/pd

Length of output: 18065


🏁 Script executed:

#!/bin/bash
set -euo pipefail

echo "== dialAddress callers =="
rg -n "dialAddress\\(|validateStoreAddress\\(" server/server.go server -S

echo "== context around validate/caller =="
file=$(rg -l "func validateStoreAddress" server)
echo "$file"
wc -l "$file"
sed -n '800,870p' "$file"
rg -n "validateStoreAddress|dialAddress" server -S

echo "== probe dependency availability =="
rg -n "github.com/probing-probe/ping|probing|NewPinger" go.mod go.sum server tests -S

Repository: tikv/pd

Length of output: 3406


🌐 Web query:

github.com/prometheus-community/pro-bing NewPinger Count Timeout Statistics PacketsRecv Run behavior ICMP ignored interfaces documentation

💡 Result:

The pro-bing library is a Go package for performing ICMP echo (ping) operations [1][2]. Below is a summary of its behavior and configuration based on official source code and documentation. NewPinger and Run Behavior The NewPinger(host string) function initializes a Pinger struct for a specific host [3][4]. The Run method initiates the probing loop [4]. The pinger operates by sending ICMP Echo Request packets and waiting for responses [2]. It runs until a specified count is reached, a timeout occurs, or the operation is externally interrupted [5]. Count and Timeout - Count: The Count field determines how many packets the pinger should send before stopping. If Count is not set (default -1), the pinger operates indefinitely until interrupted [5]. - Timeout: The Timeout field specifies a duration after which the pinger will stop, regardless of the number of packets sent or received [5]. Statistics The Statistics struct tracks the result of the operation, including [5]: - PacketsSent: Total count of packets sent. - PacketsRecv: Total count of successful responses received. - PacketsRecvDuplicates: Count of duplicate responses received. - PacketLoss: Calculated as a percentage: ((PacketsSent - PacketsRecv) / PacketsSent) * 100. Statistics can be retrieved during or after the run [5]. ICMP and Interface Management - ICMP: The library uses standard ICMP echo requests and replies [2]. It provides callbacks like OnRecv for successful responses, OnDuplicateRecv for duplicates, and OnFinish when the operation completes [2][3]. - Interfaces: The InterfaceName field in the Pinger struct allows users to bind the probe to a specific network interface [3][4]. The library internally maps the interface name to an index and sets the necessary control messages (e.g., IfIndex) on the packet connection to ensure traffic uses the specified interface [6][4]. Documentation Detailed documentation for the library is generated and available via pkg.go.dev [1][2]. For practical usage patterns, the library's repository includes a comprehensive ping utility example in the cmd/ping/ping.go file [3][7].

Citations:


Validate the configured endpoint, not just host reachability.

dialAddress() strips the port after splitting hostPort and then runs ICMP to the host only via probing.NewPinger(host), so a live host with a closed store endpoint will be accepted while only unreachable hosts are rejected.

  • Change server/grpc_service.go validation to check the actual endpoint before storing the address, or update the spec/docs to make host-level ICMP validation explicit.
  • Extend the live-host negative case in tests/server/cluster/cluster_test.go to use the closed port, not just an unreachable host.
📍 Affects 2 files
  • server/grpc_service.go#L819-L850 (this comment)
  • tests/server/cluster/cluster_test.go#L2254-L2260
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@server/grpc_service.go` around lines 819 - 850, Update server/grpc_service.go
in the dialAddress validation flow (around probing.NewPinger) to validate
connectivity to the configured host and port rather than only issuing ICMP
against the stripped host, while preserving context cancellation and error
propagation. Update tests/server/cluster/cluster_test.go at lines 2254-2260 so
the live-host negative case targets a closed store endpoint port; both sites
require changes.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

dco-signoff: yes Indicates the PR's author has signed the dco. do-not-merge/needs-triage-completed release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

server: reject unreachable store addresses in PutStore

2 participants