Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix goruntine leak when new sender fail #1197

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions mgr/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,14 @@ func NewLogExportRunner(rc RunnerConfig, wg *sync.WaitGroup, cleanChan chan<- cl
}
}
senders := make([]sender.Sender, 0)
var senderClose = false
defer func() {
if senderClose {
for _, sender := range senders {
sender.Close()
}
}
}()
for i, senderConfig := range rc.SendersConfig {
if rc.SendRaw {
senderConfig[senderConf.InnerSendRaw] = "true"
Expand All @@ -334,6 +342,7 @@ func NewLogExportRunner(rc RunnerConfig, wg *sync.WaitGroup, cleanChan chan<- cl
intervalStr, _ := rc.ReaderConfig.GetStringOr(KeySnmpReaderInterval, "30s")
interval, err := time.ParseDuration(intervalStr)
if err != nil {
senderClose = true
return nil, err
}
senderConfig[senderConf.KeyCollectInterval] = fmt.Sprintf("%d", int64(interval.Seconds()))
Expand All @@ -343,26 +352,29 @@ func NewLogExportRunner(rc RunnerConfig, wg *sync.WaitGroup, cleanChan chan<- cl
}
senderConfig, err := setPandoraServerConfig(senderConfig, serverConfigs)
if err != nil {
senderClose = true
return nil, err
}
s, err := sr.NewSender(senderConfig, meta.FtSaveLogPath())
if err != nil {
senderClose = true
return nil, err
}
senders = append(senders, s)
delete(rc.SendersConfig[i], senderConf.InnerUserAgent)
delete(rc.SendersConfig[i], senderConf.KeyPandoraDescription)
delete(rc.SendersConfig[i], senderConf.InnerSendRaw)
}

senderCnt := len(senders)
router, err := router.NewSenderRouter(rc.Router, senderCnt)
if err != nil {
senderClose = true
return nil, fmt.Errorf("runner %v add sender router error, %v", rc.RunnerName, err)
}
runner, err = NewLogExportRunnerWithService(runnerInfo, wg, rd, cl, ps, transformers, senders, router, meta)
if err != nil {
return runner, err
senderClose = true
return nil, err
}
if runner.LogAudit {
if rc.AuditChan == nil {
Expand Down