Skip to content

Commit

Permalink
Merge pull request #126 from taosdata/fix/TS-4379-3.1
Browse files Browse the repository at this point in the history
fix loop auto restart when authentication failed
  • Loading branch information
sheyanjie-qq authored Jul 12, 2024
2 parents 6436309 + e8c28d9 commit 83a0759
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
13 changes: 13 additions & 0 deletions db/connector.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@ import (
"context"
"database/sql"
"fmt"
"os"
"strings"

_ "github.com/taosdata/driver-go/v3/taosRestful"
"github.com/taosdata/taoskeeper/infrastructure/log"
)

type Connector struct {
Expand All @@ -17,6 +20,8 @@ type Data struct {
Data [][]interface{} `json:"data"`
}

var dbLogger = log.GetLogger("db")

func NewConnector(username, password, host string, port int, usessl bool) (*Connector, error) {
var protocol string
if usessl {
Expand Down Expand Up @@ -48,6 +53,10 @@ func NewConnectorWithDb(username, password, host string, port int, dbname string
func (c *Connector) Exec(ctx context.Context, sql string) (int64, error) {
res, err := c.db.ExecContext(ctx, sql)
if err != nil {
if strings.Contains(err.Error(), "Authentication failure") {
dbLogger.Error("Authentication failure")
os.Exit(1)
}
return 0, err
}
return res.RowsAffected()
Expand All @@ -56,6 +65,10 @@ func (c *Connector) Exec(ctx context.Context, sql string) (int64, error) {
func (c *Connector) Query(ctx context.Context, sql string) (*Data, error) {
rows, err := c.db.QueryContext(ctx, sql)
if err != nil {
if strings.Contains(err.Error(), "Authentication failure") {
dbLogger.Error("Authentication failure")
os.Exit(1)
}
return nil, err
}
data := &Data{}
Expand Down
4 changes: 4 additions & 0 deletions taoskeeper.service
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,11 @@ Type=simple
ExecStart=/usr/bin/taoskeeper
TimeoutSec=0
RestartSec=2
StandardOutput=null
StandardError=journal
Restart=always
StartLimitBurst=3
StartLimitInterval=60s

[Install]
WantedBy=multi-user.target

0 comments on commit 83a0759

Please sign in to comment.