Skip to content

Commit

Permalink
add recon
Browse files Browse the repository at this point in the history
  • Loading branch information
sunface committed May 9, 2019
1 parent 9cf2187 commit 16df46e
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 7 deletions.
13 changes: 10 additions & 3 deletions agent/service/collector.go
Expand Up @@ -45,8 +45,8 @@ func (c *Collector) add(key, addr string) error {
}
c.RUnlock()
// 新链接启动
go newClient.init(addr)

go newClient.init()
logger.Info("new Conn", zap.String("addr", newClient.addr), zap.String("key", ruleKey))
// 保存key
c.key = ruleKey
}
Expand All @@ -68,9 +68,16 @@ func (c *Collector) add(key, addr string) error {
}

c.RUnlock()
go newClient.init(addr)
go newClient.init()
logger.Info("new Conn", zap.String("addr", newClient.addr), zap.String("key", ruleKey))
// 保存key
c.key = ruleKey
} else {
// 重连
if !newClient.isStart {
go newClient.init()
logger.Info("client reConn", zap.String("addr", newClient.addr), zap.String("key", ruleKey))
}
}

return nil
Expand Down
6 changes: 3 additions & 3 deletions agent/service/network.go
Expand Up @@ -30,7 +30,7 @@ func newtcpClient(addr string) *tcpClient {
}

// init 初始化链接
func (t *tcpClient) init(addr string) error {
func (t *tcpClient) init() error {
var err error
quitC := make(chan bool, 1)
// 定时器
Expand All @@ -51,9 +51,9 @@ func (t *tcpClient) init(addr string) error {
ticker.Stop()
}()

t.conn, err = net.Dial("tcp", addr)
t.conn, err = net.Dial("tcp", t.addr)
if err != nil {
logger.Warn("tcp connect", zap.String("err", err.Error()), zap.String("addr", addr))
logger.Warn("tcp connect", zap.String("err", err.Error()), zap.String("addr", t.addr))
return err
}

Expand Down
2 changes: 1 addition & 1 deletion collector/collector.yaml
Expand Up @@ -4,7 +4,7 @@ common:
admintoken: "tracing.dev"

collector:
addr: "127.0.0.1:8081"
addr: "127.0.0.1:8082"
# addr: "10.77.0.125:8082"
# addr: "10.50.14.236:8082"
timeout: 30
Expand Down

0 comments on commit 16df46e

Please sign in to comment.