Merge pull request #989 from AkihiroSuda/fix-grpchijack-race
session/grpchijack: fix racedocker-19.03
commit
cae99e0a36
|
@ -46,6 +46,7 @@ type conn struct {
|
|||
|
||||
closedOnce sync.Once
|
||||
readMu sync.Mutex
|
||||
writeMu sync.Mutex
|
||||
err error
|
||||
closeCh chan struct{}
|
||||
}
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue