You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beam.apache.org by da...@apache.org on 2024/05/03 22:31:02 UTC

(beam) branch master updated: Avoid json Unmarshal on proto CancelJobRequest (#31178)

This is an automated email from the ASF dual-hosted git repository.

damondouglas pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/beam.git


The following commit(s) were added to refs/heads/master by this push:
     new e64c3596253 Avoid json Unmarshal on proto CancelJobRequest (#31178)
e64c3596253 is described below

commit e64c3596253c80ade845bf8765e6f7e04b8c57f1
Author: Damon <da...@users.noreply.github.com>
AuthorDate: Fri May 3 15:30:55 2024 -0700

    Avoid json Unmarshal on proto CancelJobRequest (#31178)
---
 sdks/go/pkg/beam/runners/prism/internal/web/web.go | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/sdks/go/pkg/beam/runners/prism/internal/web/web.go b/sdks/go/pkg/beam/runners/prism/internal/web/web.go
index baa14428aaa..f0002d850d9 100644
--- a/sdks/go/pkg/beam/runners/prism/internal/web/web.go
+++ b/sdks/go/pkg/beam/runners/prism/internal/web/web.go
@@ -373,8 +373,12 @@ 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 *jobpb.CancelJobRequest
+	var cancelRequest *cancelJobRequest
 	if r.Method != http.MethodPost {
 		http.Error(w, http.StatusText(http.StatusMethodNotAllowed), http.StatusMethodNotAllowed)
 		return
@@ -395,7 +399,10 @@ func (h *jobCancelHandler) ServeHTTP(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
-	resp, err := h.Jobcli.Cancel(r.Context(), cancelRequest)
+	// 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