From 3cc3895b78f563f19952dfc3f26754a7a474ab5e Mon Sep 17 00:00:00 2001 From: liulei Date: Thu, 6 Jan 2022 09:57:00 +0800 Subject: [PATCH] fix dtmsrv(not contain subpackage) relevant golangci lint error --- dtmsvr/cron.go | 4 ++-- dtmsvr/svr.go | 9 +++++++-- dtmsvr/trans_process.go | 7 ++++++- dtmsvr/trans_type_saga.go | 3 ++- dtmsvr/utils.go | 6 ++++-- 5 files changed, 21 insertions(+), 8 deletions(-) diff --git a/dtmsvr/cron.go b/dtmsvr/cron.go index 8b1520a63..66ff0b5b9 100644 --- a/dtmsvr/cron.go +++ b/dtmsvr/cron.go @@ -17,10 +17,10 @@ import ( ) // NowForwardDuration will be set in test, trans may be timeout -var NowForwardDuration time.Duration = time.Duration(0) +var NowForwardDuration = time.Duration(0) // CronForwardDuration will be set in test. cron will fetch trans which expire in CronForwardDuration -var CronForwardDuration time.Duration = time.Duration(0) +var CronForwardDuration = time.Duration(0) // CronTransOnce cron expired trans. use expireIn as expire time func CronTransOnce() (gid string) { diff --git a/dtmsvr/svr.go b/dtmsvr/svr.go index f891a6fa8..7f141dfde 100644 --- a/dtmsvr/svr.go +++ b/dtmsvr/svr.go @@ -27,7 +27,12 @@ func StartSvr() { app = httpMetrics(app) addRoute(app) logger.Infof("dtmsvr listen at: %d", conf.HttpPort) - go app.Run(fmt.Sprintf(":%d", conf.HttpPort)) + go func() { + err := app.Run(fmt.Sprintf(":%d", conf.HttpPort)) + if err != nil { + logger.Errorf("start server err: %v", err) + } + }() lis, err := net.Listen("tcp", fmt.Sprintf(":%d", conf.GrpcPort)) logger.FatalIfError(err) @@ -60,8 +65,8 @@ var UpdateBranchAsyncInterval = 200 * time.Millisecond var updateBranchAsyncChan chan branchStatus = make(chan branchStatus, 1000) func updateBranchAsync() { + defer dtmutil.RecoverPanic(nil) for { // flush branches every second - defer dtmutil.RecoverPanic(nil) updates := []TransBranch{} started := time.Now() checkInterval := 20 * time.Millisecond diff --git a/dtmsvr/trans_process.go b/dtmsvr/trans_process.go index db6243c4d..fc4851363 100644 --- a/dtmsvr/trans_process.go +++ b/dtmsvr/trans_process.go @@ -31,7 +31,12 @@ func (t *TransGlobal) process(branches []TransBranch) map[string]interface{} { } if !t.WaitResult { - go t.processInner(branches) + go func() { + err := t.processInner(branches) + if err != nil { + logger.Errorf("processInner err: %v", err) + } + }() return dtmcli.MapSuccess } submitting := t.Status == dtmcli.StatusSubmitted diff --git a/dtmsvr/trans_type_saga.go b/dtmsvr/trans_type_saga.go index a02e8bc3d..abaa80169 100644 --- a/dtmsvr/trans_type_saga.go +++ b/dtmsvr/trans_type_saga.go @@ -21,7 +21,8 @@ type transSagaProcessor struct { func init() { registorProcessorCreator("saga", func(trans *TransGlobal) transProcessor { - return &transSagaProcessor{TransGlobal: trans} }) + return &transSagaProcessor{TransGlobal: trans} + }) } func (t *transSagaProcessor) GenBranches() []TransBranch { diff --git a/dtmsvr/utils.go b/dtmsvr/utils.go index c52dce0aa..3afac50b7 100644 --- a/dtmsvr/utils.go +++ b/dtmsvr/utils.go @@ -24,17 +24,17 @@ type branchStatus struct { finishTime *time.Time } -var p2e = dtmimp.P2E var e2p = dtmimp.E2P var conf = &config.Config +// GetStore returns storage.Store func GetStore() storage.Store { return registry.GetStore() } // TransProcessedTestChan only for test usage. when transaction processed once, write gid to this chan -var TransProcessedTestChan chan string = nil +var TransProcessedTestChan chan string // GenGid generate gid, use uuid func GenGid() string { @@ -44,6 +44,8 @@ func GenGid() string { // GetTransGlobal construct trans from db func GetTransGlobal(gid string) *TransGlobal { trans := GetStore().FindTransGlobalStore(gid) + //nolint:staticcheck dtmimp.PanicIf(trans == nil, fmt.Errorf("no TransGlobal with gid: %s found", gid)) + //nolint:staticcheck return &TransGlobal{TransGlobalStore: *trans} }