Skip to content

Commit

Permalink
Merge pull request #132 from taosdata/fix/TD-30968
Browse files Browse the repository at this point in the history
add flush log
  • Loading branch information
sheyanjie-qq authored Jul 16, 2024
2 parents 4ac3a44 + f4a0bcb commit 12e4b2a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 0 deletions.
7 changes: 7 additions & 0 deletions db/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"fmt"
"os"
"strings"
"time"

_ "github.com/taosdata/driver-go/v3/taosRestful"
"github.com/taosdata/taoskeeper/infrastructure/log"
Expand Down Expand Up @@ -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
Expand All @@ -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
Expand Down
6 changes: 6 additions & 0 deletions system/program.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

0 comments on commit 12e4b2a

Please sign in to comment.