Skip to content

Commit

Permalink
fix(mysql): dbactuator deploy crond 没有正确关闭 http response close #1423
Browse files Browse the repository at this point in the history
  • Loading branch information
xfwduke authored and ymakedaq committed Oct 17, 2023
1 parent e794e27 commit 44202b7
Showing 1 changed file with 24 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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())
}
Expand All @@ -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
Expand All @@ -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)

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 44202b7

Please sign in to comment.