Skip to content

fix(ctl): add HTTP client timeout to prevent kmeshctl commands hanging - #1944

Merged
kmesh-bot merged 1 commit into
kmesh-net:mainfrom
Norway-02:fix/ctl-admin-http-timeout
Sep 17, 2026
Merged

kmesh-bot merged 1 commit into
kmesh-net:mainfrom
Norway-02:fix/ctl-admin-http-timeout

Conversation

@Norway-02

Copy link
Copy Markdown
Contributor

What type of PR is this?
/kind bug

What this PR does / why we need it:
kmeshctl log, kmeshctl version, kmeshctl dump, kmeshctl authz, and kmeshctl monitoring send administrative requests to a port-forwarded kmesh-daemon endpoint using the Go default HTTP client (http.Get or &http.Client{} with zero timeout).

If the port-forward tunnel stalls or the daemon is unresponsive, these commands block indefinitely with no feedback to the user. Additionally, ctl/dump/dump.go continued execution after port forwarder startup failures instead of exiting.

This PR introduces utils.NewAdminHTTPClient() in ctl/utils with a default 10-second timeout (DefaultAdminHTTPTimeout), updates kmeshctl admin call sites to use this client, and ensures ctl/dump exits cleanly on port-forward failure. Unit tests are added in ctl/utils/utils_test.go to verify timeout behavior.

Which issue(s) this PR fixes:
Fixes #1781

Special notes for your reviewer:

  • Changes are strictly isolated to ctl/.
  • Tested locally with go test ./ctl/... and make format.
  • This PR was prepared primarily by Claude Code; reviewed and verified prior to submission.

Does this PR introduce a user-facing change?:

`kmeshctl` admin commands now fail with a 10s timeout error instead of hanging indefinitely when the daemon endpoint stops responding.

Signed-off-by: Norway-02 <anshulkhetade02@gmail.com>
Copilot AI lite review requested due to automatic review settings September 10, 2026 06:22
@kmesh-bot kmesh-bot added the kind/bug Something isn't working label Sep 10, 2026
@kmesh-bot

Copy link
Copy Markdown
Collaborator

Welcome @Norway-02! It looks like this is your first PR to kmesh-net/kmesh 🎉

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.

Warning

Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.

Pull request overview

This PR prevents kmeshctl admin commands from hanging indefinitely by introducing a shared HTTP client with a default timeout and updating admin request call sites to use it, plus fixing an error path in ctl/dump when port-forward setup fails.

Changes:

  • Add utils.NewAdminHTTPClient() with a default 10s timeout (DefaultAdminHTTPTimeout).
  • Update multiple ctl/ commands to use the timeout-configured HTTP client instead of the default/no-timeout client.
  • Add unit tests around the new admin HTTP client behavior and adjust dump behavior on port-forward failures.

Reviewed changes

Copilot reviewed 7 out of 7 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
ctl/utils/utils.go Introduces a shared admin HTTP client with a default timeout constant.
ctl/utils/utils_test.go Adds tests intended to validate the admin HTTP client timeout configuration/behavior.
ctl/version/version.go Switches version request from http.Get to the admin HTTP client.
ctl/log/log.go Switches GET/POST calls to use the admin HTTP client timeout.
ctl/monitoring/monitoring.go Switches monitoring request client to the admin HTTP client timeout.
ctl/authz/authz.go Switches authz requests to the admin HTTP client timeout.
ctl/dump/dump.go Uses admin HTTP client timeout and exits on port-forward start failure.

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

Comment thread ctl/dump/dump.go
Comment on lines 86 to 90
}
if err := fw.Start(); err != nil {
log.Errorf("failed to start port forwarder for Kmesh daemon pod %s: %v", podName, err)
os.Exit(1)
}
Comment thread ctl/utils/utils_test.go
Comment on lines +35 to +47
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
time.Sleep(200 * time.Millisecond)
w.WriteHeader(http.StatusOK)
}))
defer server.Close()

customClient := &http.Client{
Timeout: 50 * time.Millisecond,
}

resp, err := customClient.Get(server.URL)
assert.Error(t, err)
assert.Nil(t, resp)
@codecov

codecov Bot commented Sep 10, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 39.63%. Comparing base (c6357aa) to head (824a878).
⚠️ Report is 18 commits behind head on main.
see 4 files with indirect coverage changes


Continue to review full report in Codecov by Harness.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update ec501a9...824a878. Read the comment docs.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@Norway-02

Copy link
Copy Markdown
Contributor Author

/cc @LiZhenCheng9527 @YaoZengzeng

@LiZhenCheng9527

Copy link
Copy Markdown
Contributor

/retest

@LiZhenCheng9527

Copy link
Copy Markdown
Contributor

/lgtm

@LiZhenCheng9527

Copy link
Copy Markdown
Contributor

/approve

@kmesh-bot

Copy link
Copy Markdown
Collaborator

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: LiZhenCheng9527

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

The pull request process is described 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

@kmesh-bot
kmesh-bot merged commit 60881fc into kmesh-net:main Sep 17, 2026
13 of 16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

kmeshctl admin commands can hang indefinitely due to missing HTTP client timeouts

4 participants