Merge pull request #859 from milosgajdos83/handle-channel-conn-errors
Handle tunnel session Accept errors gracefully
This commit is contained in:
commit
3759c9c091
@ -19,6 +19,7 @@ import (
|
|||||||
"github.com/micro/go-micro/transport"
|
"github.com/micro/go-micro/transport"
|
||||||
"github.com/micro/go-micro/tunnel"
|
"github.com/micro/go-micro/tunnel"
|
||||||
tun "github.com/micro/go-micro/tunnel/transport"
|
tun "github.com/micro/go-micro/tunnel/transport"
|
||||||
|
"github.com/micro/go-micro/util/backoff"
|
||||||
"github.com/micro/go-micro/util/log"
|
"github.com/micro/go-micro/util/log"
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -266,15 +267,26 @@ func (n *network) handleNetConn(sess tunnel.Session, msg chan *transport.Message
|
|||||||
|
|
||||||
// acceptNetConn accepts connections from NetworkChannel
|
// acceptNetConn accepts connections from NetworkChannel
|
||||||
func (n *network) acceptNetConn(l tunnel.Listener, recv chan *transport.Message) {
|
func (n *network) acceptNetConn(l tunnel.Listener, recv chan *transport.Message) {
|
||||||
|
var i int
|
||||||
for {
|
for {
|
||||||
// accept a connection
|
// accept a connection
|
||||||
conn, err := l.Accept()
|
conn, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Network tunnel [%s] accept error: %v", NetworkChannel, err)
|
sleep := backoff.Do(i)
|
||||||
|
log.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep)
|
||||||
|
time.Sleep(sleep)
|
||||||
|
if i > 5 {
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-n.closed:
|
case <-n.closed:
|
||||||
|
if err := conn.Close(); err != nil {
|
||||||
|
log.Debugf("Network tunnel [%s] failed to close connection: %v", NetworkChannel, err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
// go handle NetworkChannel connection
|
// go handle NetworkChannel connection
|
||||||
@ -555,15 +567,27 @@ func (n *network) handleCtrlConn(sess tunnel.Session, msg chan *transport.Messag
|
|||||||
|
|
||||||
// acceptCtrlConn accepts connections from ControlChannel
|
// acceptCtrlConn accepts connections from ControlChannel
|
||||||
func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *transport.Message) {
|
func (n *network) acceptCtrlConn(l tunnel.Listener, recv chan *transport.Message) {
|
||||||
|
var i int
|
||||||
for {
|
for {
|
||||||
// accept a connection
|
// accept a connection
|
||||||
conn, err := l.Accept()
|
conn, err := l.Accept()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Debugf("Network tunnel [%s] accept error: %v", ControlChannel, err)
|
sleep := backoff.Do(i)
|
||||||
|
log.Debugf("Network tunnel [%s] accept error: %v, backing off for %v", ControlChannel, err, sleep)
|
||||||
|
time.Sleep(sleep)
|
||||||
|
if i > 5 {
|
||||||
|
// reset the counter
|
||||||
|
i = 0
|
||||||
|
}
|
||||||
|
i++
|
||||||
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-n.closed:
|
case <-n.closed:
|
||||||
|
if err := conn.Close(); err != nil {
|
||||||
|
log.Debugf("Network tunnel [%s] failed to close connection: %v", ControlChannel, err)
|
||||||
|
}
|
||||||
return
|
return
|
||||||
default:
|
default:
|
||||||
// go handle ControlChannel connection
|
// go handle ControlChannel connection
|
||||||
|
Loading…
Reference in New Issue
Block a user