我在測試我的項目時遇到了 DATA RACE 警告,想知道是否有人愿意幫助我破譯這個問題。我過去從未嘗試過測試 go 例程,我發現很難全神貫注于數據競爭。我在未解決問題的描述中提供了一個鏈接,并在問題描述中提供了跟蹤。我真的很感激一些幫助,只是從學習調試類似問題和為將來的 go 例程編寫更好的測試方面。https://github.com/nitishm/vegeta-server/issues/52下面還提供了跟蹤的片段=== RUN Test_dispatcher_Cancel_Error_completedINFO[0000] creating new dispatcher component=dispatcherINFO[0000] starting dispatcher component=dispatcherINFO[0000] dispatching new attack ID=d63a79ac-6f51-486e-845d-077c8c76168a Status=scheduled component=dispatcher==================WARNING: DATA RACERead at 0x00c0000f8d68 by goroutine 8: vegeta-server/internal/dispatcher.(*task).Complete() /Users/nitishm/vegeta-server/internal/dispatcher/task.go:116 +0x61 vegeta-server/internal/dispatcher.run() /Users/nitishm/vegeta-server/internal/dispatcher/task.go:213 +0x17aPrevious write at 0x00c0000f8d68 by goroutine 7: vegeta-server/internal/dispatcher.(*task).Run() /Users/nitishm/vegeta-server/internal/dispatcher/task.go:107 +0x12a vegeta-server/internal/dispatcher.(*dispatcher).Run() /Users/nitishm/vegeta-server/internal/dispatcher/dispatcher.go:109 +0xb5fGoroutine 8 (running) created at: vegeta-server/internal/dispatcher.(*task).Run() /Users/nitishm/vegeta-server/internal/dispatcher/task.go:105 +0x11c vegeta-server/internal/dispatcher.(*dispatcher).Run() /Users/nitishm/vegeta-server/internal/dispatcher/dispatcher.go:109 +0xb5fGoroutine 7 (running) created at: vegeta-server/internal/dispatcher.Test_dispatcher_Cancel_Error_completed() /Users/nitishm/vegeta-server/internal/dispatcher/dispatcher_test.go:249 +0x545 testing.tRunner() /usr/local/go/src/testing/testing.go:827 +0x162
1 回答

交互式愛情
TA貢獻1712條經驗 獲得超3個贊
據我所知:
Read at 0x00c0000f8d68 by goroutine 8:
和Previous write at 0x00c0000f8d68 by goroutine 7
意味著 goroutines8
和7
正在讀取和寫入相同的位置。如果您查看錯誤指向的行:
goroutine 8
上116
:
if?t.status?!=?models.AttackResponseStatusRunning?{
goroutine 7
上107
:
t.status?=?models.AttackResponseStatusRunning
您可以看到 goroutinestask
在沒有任何同步的情況下訪問 的狀態,正如您已經知道的那樣,這可能會導致競爭條件。
因此,如果您的程序允許多個 goroutine 訪問單個任務,您需要確保不會發生數據競爭,例如使用互斥鎖。
- 1 回答
- 0 關注
- 146 瀏覽
添加回答
舉報
0/150
提交
取消