Browse code

Fixed the inconsistence and also a potential data race in pkg/ioutils/bytespipe.go: bp.closeErr is read/write 8 times; 7 out of 8 times it is protected by bp.mu.Lock(); 1 out of 8 times it is read without a Lock

Signed-off-by: lzhfromutsc <lzhfromustc@gmail.com>

lzhfromutsc authored on 2019/07/02 03:38:38
Showing 1 changed files
... ...
@@ -128,8 +128,9 @@ func (bp *BytesPipe) Read(p []byte) (n int, err error) {
128 128
 	bp.mu.Lock()
129 129
 	if bp.bufLen == 0 {
130 130
 		if bp.closeErr != nil {
131
+			err := bp.closeErr
131 132
 			bp.mu.Unlock()
132
-			return 0, bp.closeErr
133
+			return 0, err
133 134
 		}
134 135
 		bp.wait.Wait()
135 136
 		if bp.bufLen == 0 && bp.closeErr != nil {