Skip to content

Commit

Permalink
session/grpchijack: fix race
Browse files Browse the repository at this point in the history
Signed-off-by: Akihiro Suda <akihiro.suda.cz@hco.ntt.co.jp>
  • Loading branch information
AkihiroSuda committed May 8, 2019
1 parent 97b4b9a commit 243351a
Showing 1 changed file with 5 additions and 0 deletions.
5 changes: 5 additions & 0 deletions session/grpchijack/dial.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@ type conn struct {

closedOnce sync.Once
readMu sync.Mutex
writeMu sync.Mutex
err error
closeCh chan struct{}
}
Expand Down Expand Up @@ -79,6 +80,8 @@ func (c *conn) Read(b []byte) (n int, err error) {
}

func (c *conn) Write(b []byte) (int, error) {
c.writeMu.Lock()
defer c.writeMu.Unlock()
m := &controlapi.BytesMessage{Data: b}
if err := c.stream.SendMsg(m); err != nil {
return 0, err
Expand All @@ -93,7 +96,9 @@ func (c *conn) Close() (err error) {
}()

if cs, ok := c.stream.(grpc.ClientStream); ok {
c.writeMu.Lock()
err = cs.CloseSend()
c.writeMu.Unlock()
if err != nil {
return
}
Expand Down

0 comments on commit 243351a

Please sign in to comment.