lib/relay: Close invitation channel in all error cases (fixes #3726)
This commit is contained in:
parent
f60b424d70
commit
38d28c3f4a
@ -47,6 +47,8 @@ import (
|
|||||||
"github.com/syncthing/syncthing/lib/upgrade"
|
"github.com/syncthing/syncthing/lib/upgrade"
|
||||||
|
|
||||||
"github.com/thejerf/suture"
|
"github.com/thejerf/suture"
|
||||||
|
|
||||||
|
_ "net/http/pprof" // Need to import this to support STPROFILER.
|
||||||
)
|
)
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
|||||||
@ -44,6 +44,7 @@ func (t *relayListener) Serve() {
|
|||||||
t.mut.Unlock()
|
t.mut.Unlock()
|
||||||
|
|
||||||
clnt, err := client.NewClient(t.uri, t.tlsCfg.Certificates, nil, 10*time.Second)
|
clnt, err := client.NewClient(t.uri, t.tlsCfg.Certificates, nil, 10*time.Second)
|
||||||
|
invitations := clnt.Invitations()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.mut.Lock()
|
t.mut.Lock()
|
||||||
t.err = err
|
t.err = err
|
||||||
@ -62,7 +63,7 @@ func (t *relayListener) Serve() {
|
|||||||
|
|
||||||
for {
|
for {
|
||||||
select {
|
select {
|
||||||
case inv, ok := <-t.client.Invitations():
|
case inv, ok := <-invitations:
|
||||||
if !ok {
|
if !ok {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|||||||
@ -48,6 +48,7 @@ func newDynamicClient(uri *url.URL, certs []tls.Certificate, invitations chan pr
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *dynamicClient) Serve() {
|
func (c *dynamicClient) Serve() {
|
||||||
|
defer c.cleanup()
|
||||||
c.mut.Lock()
|
c.mut.Lock()
|
||||||
c.stop = make(chan struct{})
|
c.stop = make(chan struct{})
|
||||||
c.mut.Unlock()
|
c.mut.Unlock()
|
||||||
@ -75,8 +76,6 @@ func (c *dynamicClient) Serve() {
|
|||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
defer c.cleanup()
|
|
||||||
|
|
||||||
var addrs []string
|
var addrs []string
|
||||||
for _, relayAnn := range ann.Relays {
|
for _, relayAnn := range ann.Relays {
|
||||||
ruri, err := url.Parse(relayAnn.URL)
|
ruri, err := url.Parse(relayAnn.URL)
|
||||||
|
|||||||
@ -63,6 +63,7 @@ func newStaticClient(uri *url.URL, certs []tls.Certificate, invitations chan pro
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (c *staticClient) Serve() {
|
func (c *staticClient) Serve() {
|
||||||
|
defer c.cleanup()
|
||||||
c.stop = make(chan struct{})
|
c.stop = make(chan struct{})
|
||||||
c.stopped = make(chan struct{})
|
c.stopped = make(chan struct{})
|
||||||
defer close(c.stopped)
|
defer close(c.stopped)
|
||||||
@ -156,10 +157,6 @@ func (c *staticClient) Serve() {
|
|||||||
} else {
|
} else {
|
||||||
c.err = nil
|
c.err = nil
|
||||||
}
|
}
|
||||||
if c.closeInvitationsOnFinish {
|
|
||||||
close(c.invitations)
|
|
||||||
c.invitations = make(chan protocol.SessionInvitation)
|
|
||||||
}
|
|
||||||
c.mut.Unlock()
|
c.mut.Unlock()
|
||||||
return
|
return
|
||||||
|
|
||||||
@ -209,6 +206,15 @@ func (c *staticClient) Invitations() chan protocol.SessionInvitation {
|
|||||||
return inv
|
return inv
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func (c *staticClient) cleanup() {
|
||||||
|
c.mut.Lock()
|
||||||
|
if c.closeInvitationsOnFinish {
|
||||||
|
close(c.invitations)
|
||||||
|
c.invitations = make(chan protocol.SessionInvitation)
|
||||||
|
}
|
||||||
|
c.mut.Unlock()
|
||||||
|
}
|
||||||
|
|
||||||
func (c *staticClient) connect() error {
|
func (c *staticClient) connect() error {
|
||||||
if c.uri.Scheme != "relay" {
|
if c.uri.Scheme != "relay" {
|
||||||
return fmt.Errorf("Unsupported relay schema: %v", c.uri.Scheme)
|
return fmt.Errorf("Unsupported relay schema: %v", c.uri.Scheme)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user