当您向通道发送一条消息并关闭它时,是否存在数据争用?

I encountered a data race , like this

WARNING: DATA RACE
11652 Read by goroutine 14:
11653   runtime.chansend()
11654       /usr/local/go/src/pkg/runtime/chan.c:155 +0x0
            ...
11657
11658 Previous write by goroutine 13:
11659   runtime.closechan()
11660       /usr/local/go/src/pkg/runtime/chan.c:1232 +0x0
            ...

The channel has a lock, why is there a data race?

A channel is being written to after it has been closed. Even if there were just a single goroutine, you'd see a panic.

package main

func main() {
    c := make(chan struct{})
    close(c)
    c <- struct{}{}  // should panic!
}

What you've got is a variety of this, but with one goroutine closing, and the other goroutine is trying to write afterwards. The race detector is properly reporting this as a data race.

Why is the channel being closed in your program?