Skip to content

Commit e7d0a6a

Browse files
serathiushenrybear327
authored andcommitted
Fix race condition in robustness watch creation due to slices reallocation
Signed-off-by: Marek Siarkowicz <[email protected]>
1 parent 4b16856 commit e7d0a6a

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

tests/robustness/client/client.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -306,18 +306,22 @@ func (c *RecordingClient) watch(ctx context.Context, request model.WatchRequest)
306306
}
307307
respCh := make(chan clientv3.WatchResponse)
308308

309+
responses := []model.WatchResponse{}
309310
c.watchMux.Lock()
310311
c.watchOperations = append(c.watchOperations, model.WatchOperation{
311312
Request: request,
312-
Responses: []model.WatchResponse{},
313+
Responses: responses,
313314
})
314315
index := len(c.watchOperations) - 1
315316
c.watchMux.Unlock()
316317

317318
go func() {
318319
defer close(respCh)
319320
for r := range c.client.Watch(ctx, request.Key, ops...) {
320-
c.watchOperations[index].Responses = append(c.watchOperations[index].Responses, ToWatchResponse(r, c.baseTime))
321+
responses = append(responses, ToWatchResponse(r, c.baseTime))
322+
c.watchMux.Lock()
323+
c.watchOperations[index].Responses = responses
324+
c.watchMux.Unlock()
321325
select {
322326
case respCh <- r:
323327
case <-ctx.Done():

0 commit comments

Comments
 (0)