apache/beam · error
could not read request body
Error message
could not read request body: %w
What it means
Error built in the jobCancelHandler's ServeHTTP when io.ReadAll on the request body fails (client disconnect, connection reset, oversized body rejected). The handler wraps the underlying I/O error and returns it to the HTTP client as a 400 Bad Request response.
Solutions
- Retry the cancel request with a well-formed HTTP client and a non-empty body
- Ensure no proxy/client truncates the request body
Defensive patterns
Strategy: validation
When it happens
Trigger: Thrown at sdks/go/pkg/beam/runners/prism/internal/web/web.go:389 when the library encounters an invalid state.
Common situations: See trigger scenarios.
AI-assisted analysis of apache/beam@12126d8942 (2026-09-13).
Data as JSON: /api/errors/f68abc6386cfaa0c.
Report an issue: GitHub.
Appendix: source
Thrown at sdks/go/pkg/beam/runners/prism/internal/web/web.go:389
}
type jobCancelHandler struct {
Jobcli jobpb.JobServiceClient
}
type cancelJobRequest struct {
JobID string `json:"job_id"`
}
func (h *jobCancelHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
var cancelRequest *cancelJobRequest
if r.Method != http.MethodPost {
http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
return
}
body, err := io.ReadAll(r.Body)
if err != nil {
err = fmt.Errorf("could not read request body: %w", err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
if len(body) == 0 {
http.Error(w, "empty request body", http.StatusBadRequest)
return
}
if err := json.Unmarshal(body, &cancelRequest); err != nil {
err = fmt.Errorf("error parsing JSON: %s of request: %w", body, err)
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
// Forward JobId from POST body avoids direct json Unmarshall on composite types containing protobuf message types.
resp, err := h.Jobcli.Cancel(r.Context(), &jobpb.CancelJobRequest{
JobId: cancelRequest.JobID,
})
if err != nil {View on GitHub (pinned to 12126d8942)