feat: SUDP alway reconnect and print too much log when no data ready (#2844)

* feat: random sleep duration before reconnecting

* fix: bug
pull/2858/head
Blizard 3 years ago committed by GitHub
parent 63efa6b776
commit 452fe25cc6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -377,29 +377,33 @@ func (sv *SUDPVisitor) Run() (err error) {
func (sv *SUDPVisitor) dispatcher() { func (sv *SUDPVisitor) dispatcher() {
xl := xlog.FromContextSafe(sv.ctx) xl := xlog.FromContextSafe(sv.ctx)
var (
visitorConn net.Conn
err error
firstPacket *msg.UDPPacket
)
for { for {
// loop for get frpc to frps tcp conn
// setup worker
// wait worker to finished
// retry or exit
visitorConn, err := sv.getNewVisitorConn()
if err != nil {
// check if proxy is closed
// if checkCloseCh is close, we will return, other case we will continue to reconnect
select { select {
case firstPacket = <-sv.sendCh:
if firstPacket == nil {
xl.Info("frpc sudp visitor proxy is closed")
return
}
case <-sv.checkCloseCh: case <-sv.checkCloseCh:
xl.Info("frpc sudp visitor proxy is closed") xl.Info("frpc sudp visitor proxy is closed")
return return
default:
} }
time.Sleep(3 * time.Second) visitorConn, err = sv.getNewVisitorConn()
if err != nil {
xl.Warn("newVisitorConn to frps error: %v, try to reconnect", err) xl.Warn("newVisitorConn to frps error: %v, try to reconnect", err)
continue continue
} }
sv.worker(visitorConn) // visitorConn always be closed when worker done.
sv.worker(visitorConn, firstPacket)
select { select {
case <-sv.checkCloseCh: case <-sv.checkCloseCh:
@ -407,9 +411,10 @@ func (sv *SUDPVisitor) dispatcher() {
default: default:
} }
} }
} }
func (sv *SUDPVisitor) worker(workConn net.Conn) { func (sv *SUDPVisitor) worker(workConn net.Conn, firstPacket *msg.UDPPacket) {
xl := xlog.FromContextSafe(sv.ctx) xl := xlog.FromContextSafe(sv.ctx)
xl.Debug("starting sudp proxy worker") xl.Debug("starting sudp proxy worker")
@ -463,6 +468,14 @@ func (sv *SUDPVisitor) worker(workConn net.Conn) {
}() }()
var errRet error var errRet error
if firstPacket != nil {
if errRet = msg.WriteMsg(conn, firstPacket); errRet != nil {
xl.Warn("sender goroutine for udp work connection closed: %v", errRet)
return
}
xl.Trace("send udp package to workConn: %s", firstPacket.Content)
}
for { for {
select { select {
case udpMsg, ok := <-sv.sendCh: case udpMsg, ok := <-sv.sendCh:

Loading…
Cancel
Save