hub: review fix 5 — a window request the hub cannot read is 400; every answer says accepts_ended (version skew)
- POST /offsite/window-open answered 200 on a body it could not parse and decided the window on „count 0”; now 400 (the empty body of the oldest boxes is still „no count”). - Every answer carries accepts_ended, granted or not: a box sends its end records only to a hub that said so, so a new box never sends a large request to an older hub that reads 4 KiB. Carries the red-proof of both halves (the controller's is the next commit there). Tests seen red; 3 hub mutations seen red, 1 after a redo. Claude-Session: https://claude.ai/code/session_0159rPz1ZhFKsS53msqPYxtS
This commit is contained in:
1 parent
6d2d4bd09d
commit
45848f6ee4
8 files changed
+168
-5
No files matched your search
@@ -6,6 +6,7 @@ import (
|
||||
"errors"
|
||||
"io"
|
||||
"net/http"
|
||||
"strings"
|
||||
"time"
|
||||
|
||||
"gitea.dooplex.hu/admin/felhom-hub/internal/offsitekeys"
|
||||
@@ -141,10 +142,17 @@ func (h *Handler) handleOffsiteWindowOpen(w http.ResponseWriter, r *http.Request
|
||||
// agrees per id from its OWN records (offsitekeys/ended.go); the box's dates decide nothing.
|
||||
Ended []offsitekeys.EndedClaim `json:"ended"`
|
||||
}
|
||||
// 1 MiB: a snapshot id is 64 characters, and a removed app can hold a few hundred snapshots. A body that is cut
|
||||
// does not parse, and then nothing is claimed — the window is still decided on count_before 0, as before.
|
||||
// 1 MiB: a snapshot id is 64 characters, and a removed app can hold a few hundred snapshots.
|
||||
// A body the hub cannot read is REFUSED (review of 2026-11-15): until then a body that was cut at the read limit,
|
||||
// or was not JSON, was decided as „count_before 0” — a window opened with the smallest cap, which then refused
|
||||
// the honest plan every week. The empty body of the oldest boxes is still „no count”.
|
||||
body, _ := io.ReadAll(io.LimitReader(r.Body, 1<<20))
|
||||
_ = json.Unmarshal(body, &req)
|
||||
if len(strings.TrimSpace(string(body))) > 0 {
|
||||
if err := json.Unmarshal(body, &req); err != nil {
|
||||
http.Error(w, "the window request could not be read (not JSON, or cut)", http.StatusBadRequest)
|
||||
return
|
||||
}
|
||||
}
|
||||
ctx, cancel := context.WithTimeout(r.Context(), 2*time.Minute)
|
||||
defer cancel()
|
||||
g, err := h.offsiteKeys.OpenWindowFor(ctx, customerID, req.CountBefore, req.Ended...)
|
||||
@@ -152,6 +160,7 @@ func (h *Handler) handleOffsiteWindowOpen(w http.ResponseWriter, r *http.Request
|
||||
offsiteKeyErr(w, err)
|
||||
return
|
||||
}
|
||||
g.AcceptsEnded = true // every answer of this hub, granted or not
|
||||
writeJSON(w, http.StatusOK, g)
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user