From 44202b771a38d5fc57d4d4791dddf9932083b607 Mon Sep 17 00:00:00 2001 From: xfwduke Date: Tue, 17 Oct 2023 14:19:04 +0800 Subject: [PATCH] =?UTF-8?q?fix(mysql):=20dbactuator=20deploy=20crond=20?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E6=AD=A3=E7=A1=AE=E5=85=B3=E9=97=AD=20http?= =?UTF-8?q?=20response=20close=20#1423?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../components/mysql/deploy_mysql_crond.go | 29 +++++++++++++++---- 1 file changed, 24 insertions(+), 5 deletions(-) diff --git a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/deploy_mysql_crond.go b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/deploy_mysql_crond.go index 694ab2e9c3..89abb57a49 100644 --- a/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/deploy_mysql_crond.go +++ b/dbm-services/mysql/db-tools/dbactuator/pkg/components/mysql/deploy_mysql_crond.go @@ -196,7 +196,16 @@ func (c *DeployMySQLCrondComp) Start() (err error) { errChan := make(chan error) go func() { // 重装的时候无脑尝试关闭一次 - _, _ = http.Get("http://127.0.0.1:9999/quit") + resp, err := http.Get("http://127.0.0.1:9999/quit") + if err != nil { + logger.Error("send quit request failed for forehead start", err.Error()) + errChan <- errors.Wrap(err, "send quit request failed for forehead start") + return + } + defer func() { + _ = resp.Body.Close() + }() + time.Sleep(15 * time.Second) cmd := exec.Command( @@ -209,7 +218,7 @@ func (c *DeployMySQLCrondComp) Start() (err error) { ) var stderr bytes.Buffer cmd.Stderr = &stderr - err := cmd.Run() + err = cmd.Run() if err != nil { errChan <- errors.Wrap(err, stderr.String()) } @@ -227,11 +236,12 @@ LabelSelectLoop: } case <-time.After(1 * time.Second): logger.Info("try to connect mysql-crond %d times", i) - _, err := http.Get("http://127.0.0.1:9999/entries") + resp, err := http.Get("http://127.0.0.1:9999/entries") if err != nil { logger.Info("try to connect mysql-crond %d times failed: %s", i, err.Error()) break } + _ = resp.Body.Close() started = true logger.Info("try to connect mysql-crond %d times success", i) break LabelSelectLoop @@ -245,7 +255,15 @@ LabelSelectLoop: } // 关闭前台启动的 mysql-crond - _, _ = http.Get("http://127.0.0.1:9999/quit") + resp, err := http.Get("http://127.0.0.1:9999/quit") + if err != nil { + logger.Error("send quit request failed", err.Error()) + return err + } + defer func() { + _ = resp.Body.Close() + }() + logger.Info("send quit request success") time.Sleep(15 * time.Second) @@ -291,12 +309,13 @@ LabelSelectLoop: started = false for i := 1; i <= 10; i++ { logger.Info("try to connect mysql-crond %d times", i) - _, err := http.Get("http://127.0.0.1:9999/entries") + resp, err := http.Get("http://127.0.0.1:9999/entries") if err != nil { logger.Info("try to connect mysql-crond %d times failed: %s", i, err.Error()) time.Sleep(2 * time.Second) continue } + _ = resp.Body.Close() started = true logger.Info("try to connect mysql-crond %d times success", i) break