add more log info

This commit is contained in:
fatedier
2017-04-25 00:34:14 +08:00
parent 5360febd72
commit 71f7caa1ee
8 changed files with 122 additions and 47 deletions

View File

@ -144,8 +144,8 @@ func (ctl *Control) NewWorkConn() {
// dispatch this work connection to related proxy
if pxy, ok := ctl.proxies[startMsg.ProxyName]; ok {
go pxy.InWorkConn(workConn)
workConn.Info("start a new work connection")
go pxy.InWorkConn(workConn)
} else {
workConn.Close()
}
@ -288,7 +288,7 @@ func (ctl *Control) manager() {
}
cfg, ok := ctl.pxyCfgs[m.ProxyName]
if !ok {
// it will never go to this branch
// it will never go to this branch now
ctl.Warn("[%s] no proxy conf found", m.ProxyName)
continue
}
@ -317,12 +317,12 @@ func (ctl *Control) controler() {
maxDelayTime := 30 * time.Second
delayTime := time.Second
checkInterval := 60 * time.Second
checkInterval := 30 * time.Second
checkProxyTicker := time.NewTicker(checkInterval)
for {
select {
case <-checkProxyTicker.C:
// Every 60 seconds, check which proxy registered failed and reregister it to server.
// Every 30 seconds, check which proxy registered failed and reregister it to server.
for _, cfg := range ctl.pxyCfgs {
if _, exist := ctl.proxies[cfg.GetName()]; !exist {
ctl.Info("try to reregister proxy [%s]", cfg.GetName())
@ -337,6 +337,10 @@ func (ctl *Control) controler() {
// close related channels
close(ctl.readCh)
close(ctl.sendCh)
for _, pxy := range ctl.proxies {
pxy.Close()
}
time.Sleep(time.Second)
// loop util reconnect to server success

View File

@ -18,6 +18,7 @@ import (
"fmt"
"io"
"net"
"sync"
"github.com/fatedier/frp/models/config"
"github.com/fatedier/frp/models/msg"
@ -69,7 +70,9 @@ func NewProxy(ctl *Control, pxyConf config.ProxyConf) (pxy Proxy) {
}
type BaseProxy struct {
ctl *Control
ctl *Control
closed bool
mu sync.RWMutex
log.Logger
}
@ -151,20 +154,34 @@ func (pxy *UdpProxy) Run() (err error) {
}
func (pxy *UdpProxy) Close() {
pxy.workConn.Close()
close(pxy.readCh)
close(pxy.sendCh)
pxy.mu.Lock()
defer pxy.mu.Unlock()
if !pxy.closed {
pxy.closed = true
if pxy.workConn != nil {
pxy.workConn.Close()
}
if pxy.readCh != nil {
close(pxy.readCh)
}
if pxy.sendCh != nil {
close(pxy.sendCh)
}
}
}
func (pxy *UdpProxy) InWorkConn(conn frpNet.Conn) {
if pxy.workConn != nil {
pxy.workConn.Close()
close(pxy.readCh)
close(pxy.sendCh)
}
pxy.Info("incoming a new work connection for udp proxy")
// close resources releated with old workConn
pxy.Close()
pxy.mu.Lock()
pxy.workConn = conn
pxy.readCh = make(chan *msg.UdpPacket, 64)
pxy.sendCh = make(chan *msg.UdpPacket, 64)
pxy.closed = false
pxy.mu.Unlock()
workConnReaderFn := func(conn net.Conn) {
for {
@ -174,9 +191,10 @@ func (pxy *UdpProxy) InWorkConn(conn frpNet.Conn) {
return
}
if errRet := errors.PanicToError(func() {
pxy.Trace("get udp package from workConn: %s", udpMsg.Content)
pxy.readCh <- &udpMsg
}); errRet != nil {
pxy.Info("reader goroutine for udp work connection closed")
pxy.Info("reader goroutine for udp work connection closed: %v", errRet)
return
}
}
@ -184,6 +202,7 @@ func (pxy *UdpProxy) InWorkConn(conn frpNet.Conn) {
workConnSenderFn := func(conn net.Conn) {
var errRet error
for udpMsg := range pxy.sendCh {
pxy.Trace("send udp package to workConn: %s", udpMsg.Content)
if errRet = msg.WriteMsg(conn, udpMsg); errRet != nil {
pxy.Info("sender goroutine for udp work connection closed")
return