Skip to content

Commit 7a35f32

Browse files
authored
fix Pull iterator data race (#156)
2 parents 1aeb3f8 + 865c60c commit 7a35f32

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

pkg/store/storepb/inprocess.go

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import (
77
"context"
88
"io"
99
"iter"
10+
"sync"
1011

1112
"google.golang.org/grpc"
1213
)
@@ -38,17 +39,21 @@ type inProcessClient struct {
3839
ctx context.Context
3940
next func() (*SeriesResponse, error, bool)
4041
stop func()
42+
mu sync.Mutex
4143
}
4244

4345
func newInProcessClient(ctx context.Context, next func() (*SeriesResponse, error, bool), stop func()) *inProcessClient {
4446
return &inProcessClient{
4547
ctx: ctx,
4648
next: next,
4749
stop: stop,
50+
mu: sync.Mutex{},
4851
}
4952
}
5053

5154
func (c *inProcessClient) Recv() (*SeriesResponse, error) {
55+
c.mu.Lock()
56+
defer c.mu.Unlock()
5257
resp, err, ok := c.next()
5358
if err != nil {
5459
c.stop()
@@ -68,6 +73,8 @@ func (c *inProcessClient) Context() context.Context {
6873
}
6974

7075
func (c *inProcessClient) CloseSend() error {
76+
c.mu.Lock()
77+
defer c.mu.Unlock()
7178
c.stop()
7279
return nil
7380
}

0 commit comments

Comments
 (0)