Skip to content

Commit

Permalink
Optimize graceful shutdown
Browse files Browse the repository at this point in the history
  • Loading branch information
andeya committed Oct 31, 2017
1 parent 2a1549f commit db39a01
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 8 deletions.
6 changes: 4 additions & 2 deletions peer.go
Original file line number Diff line number Diff line change
Expand Up @@ -241,9 +241,11 @@ func (p *Peer) Close() (err error) {
)
p.sessHub.Range(func(sess *session) bool {
count++
Go(func() {
if !Go(func() {
errCh <- sess.Close()
})
}) {
errCh <- sess.Close()
}
return true
})
for i := 0; i < count; i++ {
Expand Down
7 changes: 1 addition & 6 deletions session.go
Original file line number Diff line number Diff line change
Expand Up @@ -450,10 +450,6 @@ var (

// Close closes the session.
func (s *session) Close() (err error) {
if atomic.LoadInt32(&s.closed) == 1 {
return nil
}

s.closeLock.Lock()
if atomic.LoadInt32(&s.closed) == 1 {
s.closeLock.Unlock()
Expand All @@ -472,11 +468,10 @@ func (s *session) Close() (err error) {

err = s.socket.Close()

s.peer.sessHub.Delete(s.Id())
s.closeLock.Unlock()
}()

s.peer.sessHub.Delete(s.Id())

if !s.isDisconnected() {
// make sure do not disconnect because of reading timeout.
// wait for the subsequent write to complete.
Expand Down

0 comments on commit db39a01

Please sign in to comment.