diff --git a/db/connector.go b/db/connector.go index 0f09f26..3c9aa88 100644 --- a/db/connector.go +++ b/db/connector.go @@ -6,6 +6,7 @@ import ( "fmt" "os" "strings" + "time" _ "github.com/taosdata/driver-go/v3/taosRestful" "github.com/taosdata/taoskeeper/infrastructure/log" @@ -55,6 +56,9 @@ func (c *Connector) Exec(ctx context.Context, sql string) (int64, error) { if err != nil { if strings.Contains(err.Error(), "Authentication failure") { dbLogger.Error("Authentication failure") + ctxLog, cancelLog := context.WithTimeout(context.Background(), 3*time.Second) + defer cancelLog() + log.Close(ctxLog) os.Exit(1) } return 0, err @@ -67,6 +71,9 @@ func (c *Connector) Query(ctx context.Context, sql string) (*Data, error) { if err != nil { if strings.Contains(err.Error(), "Authentication failure") { dbLogger.Error("Authentication failure") + ctxLog, cancelLog := context.WithTimeout(context.Background(), 3*time.Second) + defer cancelLog() + log.Close(ctxLog) os.Exit(1) } return nil, err diff --git a/system/program.go b/system/program.go index b5343b6..ec41cc4 100644 --- a/system/program.go +++ b/system/program.go @@ -122,5 +122,11 @@ func (p *program) Stop(s service.Service) error { } logger.Println("Server exiting") + + ctxLog, cancelLog := context.WithTimeout(context.Background(), 5*time.Second) + defer cancelLog() + logger.Println("Flushing Log") + log.Close(ctxLog) + return nil }