From 5f072c6b566872a391892f3606d2e81b5d65ff1c Mon Sep 17 00:00:00 2001 From: Nikita Kryuchkov Date: Wed, 17 Jul 2019 21:50:51 +0300 Subject: [PATCH] Do not fill SetupTpChan in createTransport --- pkg/transport/manager.go | 11 ++--------- vendor/github.com/skycoin/dmsg/client.go | 10 +++++++++- vendor/github.com/skycoin/dmsg/transport.go | 4 ++++ vendor/modules.txt | 2 +- 4 files changed, 16 insertions(+), 11 deletions(-) diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index d6fe8cbaf..fdf71965e 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -339,23 +339,16 @@ func (tm *Manager) createTransport(ctx context.Context, remote cipher.PubKey, tp tm.transports[entry.ID] = mTr tm.mu.Unlock() - var setupTpChan chan Transport - var dataTpChan chan *ManagedTransport - if tm.IsSetupTransport(tr) { - setupTpChan = tm.SetupTpChan - } else { - dataTpChan = tm.DataTpChan + return mTr, nil } select { case <-tm.doneChan: return nil, io.ErrClosedPipe - case dataTpChan <- mTr: + case tm.DataTpChan <- mTr: go tm.manageTransport(ctx, mTr, factory, remote) return mTr, nil - case setupTpChan <- mTr: - return mTr, nil } } diff --git a/vendor/github.com/skycoin/dmsg/client.go b/vendor/github.com/skycoin/dmsg/client.go index 0ec707809..bd07446ed 100644 --- a/vendor/github.com/skycoin/dmsg/client.go +++ b/vendor/github.com/skycoin/dmsg/client.go @@ -256,14 +256,18 @@ func (c *ClientConn) DialTransport(ctx context.Context, clientPK cipher.PubKey) } func (c *ClientConn) close() (closed bool) { + if c == nil { + return false + } c.once.Do(func() { closed = true c.log.WithField("remoteServer", c.remoteSrv).Infoln("ClosingConnection") close(c.done) c.mx.Lock() for _, tp := range c.tps { + // Nil check is required here to keep 8192 running goroutines limit in tests with -race flag. if tp != nil { - go tp.Close() //nolint:errcheck + go tp.Close() // nolint:errcheck } } _ = c.Conn.Close() //nolint:errcheck @@ -539,6 +543,10 @@ func (c *Client) Type() string { // Close closes the dms_client and associated connections. // TODO(evaninjin): proper error handling. func (c *Client) Close() error { + if c == nil { + return nil + } + c.once.Do(func() { close(c.done) for { diff --git a/vendor/github.com/skycoin/dmsg/transport.go b/vendor/github.com/skycoin/dmsg/transport.go index 990966d0f..cc2724428 100644 --- a/vendor/github.com/skycoin/dmsg/transport.go +++ b/vendor/github.com/skycoin/dmsg/transport.go @@ -85,6 +85,10 @@ func (tp *Transport) serve() (started bool) { // 4. But as, under the mutexes protecting `inCh`/`bufCh`, checking `done` comes first, // and we know that `done` is closed before `inCh`/`bufCh`, we can guarantee that it avoids writing to closed chan. func (tp *Transport) close() (closed bool) { + if tp == nil { + return false + } + tp.doneOnce.Do(func() { closed = true diff --git a/vendor/modules.txt b/vendor/modules.txt index 7073f0d9a..5d9179f82 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -95,8 +95,8 @@ golang.org/x/crypto/internal/subtle golang.org/x/crypto/poly1305 # golang.org/x/net v0.0.0-20190620200207-3b0461eec859 golang.org/x/net/context -golang.org/x/net/proxy golang.org/x/net/nettest +golang.org/x/net/proxy golang.org/x/net/internal/socks # golang.org/x/sys v0.0.0-20190626221950-04f50cda93cb golang.org/x/sys/unix