apache/beam · error

error encoding response

Error message

error encoding response: %w

What it means

Error built in jobCancelHandler.ServeHTTP when json.NewEncoder(w).Encode of the CancelJobResponse fails while writing the HTTP response — typically because the client disconnected mid-response or the connection was closed. The error can no longer be reported to that client, so it is wrapped and logged/surfaced server-side.

Solutions

  1. Check for client-side timeouts or early disconnects and retry the request
  2. Ensure response body is fully consumed by the client
Defensive patterns

Strategy: fallback

When it happens

Trigger: Thrown at sdks/go/pkg/beam/runners/prism/internal/web/web.go:420 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/da3cccd22cbf33c6. Report an issue: GitHub.

Appendix: source

Thrown at sdks/go/pkg/beam/runners/prism/internal/web/web.go:420

	// 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 {
		statusCode := status.Code(err)
		httpCode := http.StatusInternalServerError
		if c, ok := grpcToHttpCodes[statusCode]; ok {
			httpCode = c
		}
		err = fmt.Errorf("error Cancel(%+v) = %w", cancelRequest, err)
		http.Error(w, err.Error(), httpCode)
	}

	w.Header().Add(kContentType, kApplicationJson)

	if err = json.NewEncoder(w).Encode(resp); err != nil {
		err = fmt.Errorf("error encoding response: %w", err)
		http.Error(w, err.Error(), http.StatusInternalServerError)
	}
}

// Initialize the web client to talk to the given Job Management Client.
func Initialize(ctx context.Context, port int, jobcli jobpb.JobServiceClient) error {
	assetsFs := http.FileServer(http.FS(assets))
	mux := http.NewServeMux()

	mux.Handle("/assets/", assetsFs)
	mux.Handle("/job/cancel/", &jobCancelHandler{Jobcli: jobcli})
	mux.Handle("/job/", &jobDetailsHandler{Jobcli: jobcli})
	mux.Handle("/debugz", &debugzHandler{})
	mux.Handle("/", &jobsConsoleHandler{Jobcli: jobcli})

	endpoint := fmt.Sprintf("localhost:%d", port)

	slog.Info("Serving WebUI", slog.String("endpoint", "http://"+endpoint))

View on GitHub (pinned to 12126d8942)