Skip to content

Commit

Permalink
Replace the exclusive lock with a read-write lock
Browse files Browse the repository at this point in the history
  • Loading branch information
gotoxu committed May 7, 2019
1 parent c93ca9a commit 36d65ce
Showing 1 changed file with 4 additions and 5 deletions.
9 changes: 4 additions & 5 deletions rpc/conn.go
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ type connection struct {
stopFlat int32
stopChan chan struct{}
stopWG sync.WaitGroup
sync.Mutex
sync.RWMutex
}

func (conn *connection) close() {
Expand Down Expand Up @@ -336,16 +336,15 @@ func (conn *connection) readFromStream(errChan chan error, msgChan chan *protos.
}

func (conn *connection) getStream() stream {
conn.Lock()
defer conn.Unlock()
conn.RLock()
defer conn.RUnlock()

if conn.toDie() {
return nil
}

if conn.clientStream != nil && conn.serverStream != nil {
e := errors.New("Both client and server stream are not nil, something went wrong")
logging.Errorf("%+v", e)
logging.Error("Both client and server stream are not nil, something went wrong")
}

if conn.clientStream != nil {
Expand Down

0 comments on commit 36d65ce

Please sign in to comment.