On Sat, 2022-04-30 at 22:49 -0700, Zhaoxun Yan wrote:
> I am sure it did not detect race immediately at least in my
> project, which has similar global variable race conditions, but in a
> more subtle way .
>
> For example, the checking of one global variable is from an
> incoming message from a remote host, while the changing of the global
> variable is from a crontask. They have a possibility to collide, but
> my race build did not crash because of it yet.
You have not confirmed that you are running the executable that was
built with the race detector.
However, yes it is entirely possible that the race detector can fail to
detect a potential race condition (see "How it works" in the Go blog
post that introduced it
https://go.dev/blog/race-detector). This is
because it is not a static analysis tool. If your race is infrequent it
is possible for the sequence of concurrent reads and writes to not
happen during an execution.
If you are confident that there is a potential race condition in your
code, you can either fix it or attempt to increase the frequency of the
raciness and make yourself satisfied that it is there with the race
detector and then fix it.
Dan