diff --git a/pkg/router/router.go b/pkg/router/router.go index d5b62302e..9cd06f564 100644 --- a/pkg/router/router.go +++ b/pkg/router/router.go @@ -85,6 +85,8 @@ func (r *Router) Serve(ctx context.Context) error { isAccepted, isSetup := tp.Accepted, r.IsSetupTransport(tp) r.mu.Unlock() + r.Logger.Infof("New transport: isAccepted: %v, isSetup: %v", isAccepted, isSetup) + var serve func(io.ReadWriter) error switch { case isAccepted && isSetup: diff --git a/pkg/transport/managed_transport.go b/pkg/transport/managed_transport.go index 58e09e5ff..912bab151 100644 --- a/pkg/transport/managed_transport.go +++ b/pkg/transport/managed_transport.go @@ -21,6 +21,7 @@ type ManagedTransport struct { errChan chan error isClosing int32 mu sync.RWMutex + once sync.Once readLogChan chan int writeLogChan chan int @@ -34,8 +35,8 @@ func newManagedTransport(id uuid.UUID, tr Transport, public bool, accepted bool) Accepted: accepted, doneChan: make(chan struct{}), errChan: make(chan error), - readLogChan: make(chan int), - writeLogChan: make(chan int), + readLogChan: make(chan int, 16), + writeLogChan: make(chan int, 16), LogEntry: &LogEntry{new(big.Int), new(big.Int)}, } } @@ -72,12 +73,9 @@ func (tr *ManagedTransport) Write(p []byte) (n int, err error) { // killWorker sends signal to Manager.manageTransport goroutine to exit // it's safe to call it multiple times func (tr *ManagedTransport) killWorker() { - select { - case <-tr.doneChan: - return - default: + tr.once.Do(func() { close(tr.doneChan) - } + }) } // Close closes underlying diff --git a/pkg/transport/manager.go b/pkg/transport/manager.go index 1ad99a561..80fcbc215 100644 --- a/pkg/transport/manager.go +++ b/pkg/transport/manager.go @@ -245,8 +245,6 @@ func (tm *Manager) DeleteTransport(id uuid.UUID) error { tr := tm.transports[id] delete(tm.transports, id) tm.mu.Unlock() - mgrQty := atomic.AddInt32(&tm.mgrQty, -1) - tm.Logger.Infof("Manager.DeleteTransport id: %v, mgrQty = %v", id, mgrQty) tr.Close()