Skip to content

Commit

Permalink
Changed killWorker - now it's using sync.Once
Browse files Browse the repository at this point in the history
  • Loading branch information
ayuryshev committed Jun 5, 2019
1 parent 7dabb5f commit 2ba8af0
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
2 changes: 2 additions & 0 deletions pkg/router/router.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
12 changes: 5 additions & 7 deletions pkg/transport/managed_transport.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ type ManagedTransport struct {
errChan chan error
isClosing int32
mu sync.RWMutex
once sync.Once

readLogChan chan int
writeLogChan chan int
Expand All @@ -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)},
}
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 0 additions & 2 deletions pkg/transport/manager.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down

0 comments on commit 2ba8af0

Please sign in to comment.