myxce/.wolf/bugs/bug-1961.md
Rongsong Shen f45b85c9e5
docs(buglog): record Gitea sync for bug-1958..bug-1967
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-10 10:51:33 +00:00

54 lines
2.9 KiB
Markdown

---
id: "bug-1961"
status: "fixed"
status_updated: "2026-10-10"
status_note: ""
component: "apiserver"
severity: "wrong-result"
timestamp: "2026-10-10T10:16:04Z"
last_seen: "2026-10-10T10:16:04Z"
occurrences: 1
files: ["src/frontend/apiserver/controllers/hosts.go"]
tags: ["apiserver", "hosts"]
related: []
fix_commits: ["d720132c"]
gitea_issue: 392
gitea_synced_status: "fixed"
gitea_synced_hash: "da9667fb5610"
---
# bug-1961: apiserver ControlHost writes a second response after validateHost rejected the request
## Description
**Observed:** (source reading; follow-up of the 2026-10-10 P0 fixes (bug-1936..1957))
Reported by the bug-1949 fix: `validateHost` (`controllers/hosts.go`) writes a 403 via `ReturnError` without aborting and `ControlHost` continues and writes another response (today masked by the route's RequirePermission).
**Expected:** A rejected host control stops after the first error response.
**Impact:** Wrong result / noise: double responses, possible action after a rejection if the route guard changes.
**Found by:** follow-up of the 2026-10-10 P0 fixes (bug-1936..1957)
## Environment
- OS: no /etc/os-release; Docker container; NixOS kernel; kernel Linux 6.18.33 x86_64
- libc: glibc 2.42-47 (interpreter /nix/store/wb6rhpznjfczwlwx23zmdrrw74bayxw4-glibc-2.42-47/lib/ld-linux-x86-64.so.2)
- Toolchain: gcc (GCC) 15.2.0, meson 1.9.1
- Build: asan (xce.build)
- Code: scheduler-framework @ 19be145d-dirty
- Deployment: any (found by source reading; confirmed by the RED test of the fix)
## Reproduction
1. Call ControlHost so that validateHost rejects (see the handler) with the route guard removed in a unit test; two writes occur.
- Frequency: deterministic (by code reading; confirmed by the RED test of the fix)
- Evidence: the code sites quoted in Description; no logs kept.
## Root cause
`validateHost` (`controllers/hosts.go`) wrote a 403 via `ReturnError` without aborting, so `ControlHost`'s `IsAborted()` check never fired and it wrote a second (202) response. Pre-existing.
## Fix
`validateHost` no longer writes a response: it checks `host:control` once, before the host loop (it used to check per host and not at all for an empty list), and returns an error; `ControlHost` writes a single 403 and returns; for `all` the host list is resolved first.
## Verification
- Test: `TestControlHost_RejectedWritesSingleResponse` (`controllers/hosts_handler_test.go`, route without its guard): RED `hosts_handler_test.go:61: handler wrote 2 responses, want 1`, GREEN after.
- Suites: `xce-build.sh all asan xce.build --incremental` on the merged branch, 2026-10-10: C suites Ok 157 / Fail 0; frontend Go tests ok (the build now also runs apiserver cmd, middleware, models and router)
- Live: n/a: unit/fixture-level verification; no live deployment was run
## References
- Fix commits: `d720132c` (on `scheduler-framework`)
- Found as a follow-up of the 2026-10-10 P0 fixes (bug-1936..1957)