grpc-go icon indicating copy to clipboard operation
grpc-go copied to clipboard

Data Race on the field ''items''

Open yanke-xu opened this issue 2 years ago • 3 comments

During our research on non-blocking concurrency bugs in gRPC, we discovered a potential Data Race in the program. Specifically,there are two confilicting operations on the field "items", where

the read operation at:.../grpc/internal/wrr/random.go:90, and the write operation at:.../grpc/internal/wrr/random.go:86

I don't know whether it is accurate, so I 'm looking forward to your reply.

yanke-xu avatar Jan 25 '23 14:01 yanke-xu

Can you provide a reproduction sample for this?

This would only happen if the wrr state is being logged while also being changed, so wouldn't be critical for correctness. Adding a rw.mu.RLock(); defer rw.mu.RUnlock() to the top of (*randomWRR).String would also prevent this.

dfawley avatar Jan 25 '23 17:01 dfawley

This issue is labeled as requiring an update from the reporter, and no update has been received after 6 days. If no update is provided in the next 7 days, this issue will be automatically closed.

github-actions[bot] avatar Feb 01 '23 03:02 github-actions[bot]

Is it possible for the two statements to be executed at the same time? If so, adding a rw.mu.RLock(); defer rw.mu.RUnlock() to the top of *randomWRR).String is necessary.

yanke-xu avatar Feb 06 '23 02:02 yanke-xu

Add() is always called as part of constructing the WRR object and never concurrently. Also turns out Next() is never called concurrently either. I started the PR (#5970) started out to avoid the race when accessing WRR.items in String(), but the mutex can be avoided all together for random WRR.

arvindbr8 avatar Oct 06 '23 23:10 arvindbr8