Skip to content

Commit

Permalink
Fix RouteGroup closing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
nkryuchkov committed Dec 12, 2019
1 parent d9d9288 commit e4bae52
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 6 deletions.
13 changes: 8 additions & 5 deletions pkg/router/route_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,10 +80,11 @@ type RouteGroup struct {
// 'readCh' reads in incoming packets of this route group.
// - Router should serve call '(*transport.Manager).ReadPacket' in a loop,
// and push to the appropriate '(RouteGroup).readCh'.
readCh chan []byte // push reads from Router
readBuf bytes.Buffer // for read overflow
done chan struct{}
once sync.Once
readCh chan []byte // push reads from Router
readChMu sync.Mutex
readBuf bytes.Buffer // for read overflow
done chan struct{}
once sync.Once

readDeadline deadline.PipeDeadline
writeDeadline deadline.PipeDeadline
Expand Down Expand Up @@ -256,7 +257,9 @@ func (r *RouteGroup) Close() error {

r.once.Do(func() {
close(r.done)
// close(r.readCh) // TODO(nkryuchkov): uncomment
r.readChMu.Lock()
close(r.readCh)
r.readChMu.Unlock()
})

return nil
Expand Down
4 changes: 4 additions & 0 deletions pkg/router/route_group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -465,12 +465,16 @@ func pushPackets(ctx context.Context, t *testing.T, from *transport.Manager, to
panic("malformed packet")
}

to.readChMu.Lock()
select {
case <-ctx.Done():
to.readChMu.Unlock()
return
case <-to.done:
to.readChMu.Unlock()
return
case to.readCh <- payload:
to.readChMu.Unlock()
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/router/routerclient/wrappers.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
"github.com/SkycoinProject/skywire-mainnet/pkg/routing"
)

// TODO(nkryuchkov): remove this
// TODO: remove this
// dmsgClientWrapper is a temporary workaround to make dmsg client implement `snet.Dialer`.
// The only reason to use this is because client's `Dial` returns `*dmsg.Stream` instead of `net.Conn`,
// so this stuff should be removed as soon as the func's signature changes
Expand Down

0 comments on commit e4bae52

Please sign in to comment.