Skip to content

Commit

Permalink
Fixed the race. Made wait channel boolean.
Browse files Browse the repository at this point in the history
  • Loading branch information
milosgajdos committed Aug 16, 2019
1 parent c90e1cc commit 7abdc68
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
4 changes: 2 additions & 2 deletions tunnel/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -138,17 +138,17 @@ func (t *tun) monitor() {
return
case <-reconnect.C:
for _, node := range t.options.Nodes {
t.Lock()
if _, ok := t.links[node]; !ok {
t.Lock()
link, err := t.setupLink(node)
if err != nil {
log.Debugf("Tunnel failed to setup node link to %s: %v", node, err)
t.Unlock()
continue
}
t.links[node] = link
t.Unlock()
}
t.Unlock()
}
}
}
Expand Down
22 changes: 11 additions & 11 deletions tunnel/tunnel_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,15 @@ import (
)

// testAccept will accept connections on the transport, create a new link and tunnel on top
func testAccept(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.WaitGroup) {
func testAccept(t *testing.T, tun Tunnel, wait chan bool, wg *sync.WaitGroup) {
// listen on some virtual address
tl, err := tun.Listen("test-tunnel")
if err != nil {
t.Fatal(err)
}

// receiver ready; notify sender
wait <- struct{}{}
wait <- true

// accept a connection
c, err := tl.Accept()
Expand Down Expand Up @@ -49,7 +49,7 @@ func testAccept(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.WaitGroup
}

// testSend will create a new link to an address and then a tunnel on top
func testSend(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.WaitGroup) {
func testSend(t *testing.T, tun Tunnel, wait chan bool, wg *sync.WaitGroup) {
defer wg.Done()

// wait for the listener to get ready
Expand Down Expand Up @@ -110,7 +110,7 @@ func TestTunnel(t *testing.T) {
}
defer tunA.Close()

wait := make(chan struct{})
wait := make(chan bool)

var wg sync.WaitGroup

Expand Down Expand Up @@ -140,7 +140,7 @@ func TestLoopbackTunnel(t *testing.T) {
}
defer tun.Close()

wait := make(chan struct{})
wait := make(chan bool)

var wg sync.WaitGroup

Expand All @@ -156,7 +156,7 @@ func TestLoopbackTunnel(t *testing.T) {
wg.Wait()
}

func testBrokenTunAccept(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.WaitGroup) {
func testBrokenTunAccept(t *testing.T, tun Tunnel, wait chan bool, wg *sync.WaitGroup) {
defer wg.Done()

// listen on some virtual address
Expand All @@ -166,7 +166,7 @@ func testBrokenTunAccept(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.
}

// receiver ready; notify sender
wait <- struct{}{}
wait <- true

// accept a connection
c, err := tl.Accept()
Expand Down Expand Up @@ -196,7 +196,7 @@ func testBrokenTunAccept(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.
}

// receiver ready; notify sender
wait <- struct{}{}
wait <- true

// accept a connection
c, err = tl.Accept()
Expand All @@ -214,7 +214,7 @@ func testBrokenTunAccept(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.
<-wait
}

func testBrokenTunSend(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.WaitGroup) {
func testBrokenTunSend(t *testing.T, tun Tunnel, wait chan bool, wg *sync.WaitGroup) {
defer wg.Done()

// wait for the listener to get ready
Expand Down Expand Up @@ -252,7 +252,7 @@ func testBrokenTunSend(t *testing.T, tun Tunnel, wait chan struct{}, wg *sync.Wa
// wait for the listener to receive the message
// c.Send merely enqueues the message to the link send queue and returns
// in order to verify it was received we wait for the listener to tell us
wait <- struct{}{}
wait <- true
}

func TestReconnectTunnel(t *testing.T) {
Expand Down Expand Up @@ -283,7 +283,7 @@ func TestReconnectTunnel(t *testing.T) {
t.Fatal(err)
}

wait := make(chan struct{})
wait := make(chan bool)

var wg sync.WaitGroup

Expand Down

0 comments on commit 7abdc68

Please sign in to comment.