From 08bd00839db50e4144af33c94b7eef717cd8c790 Mon Sep 17 00:00:00 2001 From: Ti Chi Robot Date: Wed, 12 Jan 2022 21:53:42 +0800 Subject: [PATCH] http_api (ticdc): fix http api 'get processor' panic. (#4117) (#4123) close pingcap/tiflow#3840 --- cdc/capture/http_errors.go | 2 +- cdc/capture/http_handler.go | 2 ++ tests/integration_tests/http_api/util/test_case.py | 11 ++++++++--- 3 files changed, 11 insertions(+), 4 deletions(-) diff --git a/cdc/capture/http_errors.go b/cdc/capture/http_errors.go index ed58b71e108..79db530429d 100644 --- a/cdc/capture/http_errors.go +++ b/cdc/capture/http_errors.go @@ -25,7 +25,7 @@ var httpBadRequestError = []*errors.Error{ cerror.ErrAPIInvalidParam, cerror.ErrSinkURIInvalid, cerror.ErrStartTsBeforeGC, cerror.ErrChangeFeedNotExists, cerror.ErrTargetTsBeforeStartTs, cerror.ErrTableIneligible, cerror.ErrFilterRuleInvalid, cerror.ErrChangefeedUpdateRefused, cerror.ErrMySQLConnectionError, - cerror.ErrMySQLInvalidConfig, + cerror.ErrMySQLInvalidConfig, cerror.ErrCaptureNotExist, } // IsHTTPBadRequestError check if a error is a http bad request error diff --git a/cdc/capture/http_handler.go b/cdc/capture/http_handler.go index a13f2ffffe2..05a332f826b 100644 --- a/cdc/capture/http_handler.go +++ b/cdc/capture/http_handler.go @@ -576,6 +576,7 @@ func (h *HTTPHandler) GetProcessor(c *gin.Context) { status, exist := statuses[captureID] if !exist { _ = c.Error(cerror.ErrCaptureNotExist.GenWithStackByArgs(captureID)) + return } positions, err := statusProvider.GetTaskPositions(ctx, changefeedID) @@ -586,6 +587,7 @@ func (h *HTTPHandler) GetProcessor(c *gin.Context) { position, exist := positions[captureID] if !exist { _ = c.Error(cerror.ErrCaptureNotExist.GenWithStackByArgs(captureID)) + return } processorDetail := &model.ProcessorDetail{CheckPointTs: position.CheckPointTs, ResolvedTs: position.ResolvedTs, Error: position.Error} diff --git a/tests/integration_tests/http_api/util/test_case.py b/tests/integration_tests/http_api/util/test_case.py index 5206bc9b8ca..382ffe1ab55 100644 --- a/tests/integration_tests/http_api/util/test_case.py +++ b/tests/integration_tests/http_api/util/test_case.py @@ -243,14 +243,19 @@ def list_processor(): # must at least one table is sync will the test success def get_processor(): - url = BASE_URL0 + "/processors" - resp = rq.get(url, cert=CERT, verify=VERIFY) + base_url = BASE_URL0 + "/processors" + resp = rq.get(base_url, cert=CERT, verify=VERIFY) assert resp.status_code == rq.codes.ok data = resp.json()[0] - url = url + "/" + data["changefeed_id"] + "/" + data["capture_id"] + url = base_url + "/" + data["changefeed_id"] + "/" + data["capture_id"] resp = rq.get(url, cert=CERT, verify=VERIFY) assert resp.status_code == rq.codes.ok + # test capture_id error and cdc server no panic + url = base_url + "/" + data["changefeed_id"] + "/" + "non-exist-capture-id" + resp = rq.get(url, cert=CERT, verify=VERIFY) + assert resp.status_code == rq.codes.bad_request + print("pass test: get processors")