feat(go_port_test): reproduce test of race condition of shutdown with non-empty queue - #880
Schrodinger257 wants to merge 2 commits into
Conversation
… non-empty queue this test reproduce the following problem. when calling Destroy() with non-empty queue a deadlock occur and block on either Call() waits for <-ret to return a value or Destroy() block on wg.Wait(). you can see and verify the profile file using "go tools pprof filename.pprof" command
|
I need the instrumentation you have used included into the tests so we can verify in the CI that it fails, if you need help of how to define tests in cmake I can help you on that. |
I used go theead sanitizer using -race flag in go test . -race which showed a data race warning and used a tool in go called pprof that creates a profiles that monitor a specific item like heap memory or goroutines. The profile i used is goroutine profile. I imported the library then captured the goroutine profile using pprof.Lookup("goroutine") then stored it in a .pprof file then displayed it using command go tool pprof file_name.pprof and found the 100 leaked goroutines. I tried to use cmake tests using c thread sanitizer but i got a segfault as c and go both uses the same sanitizer runtime which created a conflict. |
|
Everything you used must be added to the project so it's tested during CI. What are all the commands did you use? |
go test . -race |
What does the second command? |
the second command is not important it only shows the number of leaked goroutines and do not trigger any warnings or failures signs. do you still want to use the second command in cmake ? |
Yes I will show it, this can give us more information in the CI when debugging, the test must fail if the go test fails or there is data races or leaks. If you need you can define how a test passes by filtering the text in the output of the command. I mean if it doesn't do exit 1 or similar when it fails... |
okay i will try to implement cmake test |
|
fixed go cmake tests and added support of thread sanitizer and goroutine profile to track leaked goroutines with limit of 20 goroutines, more than 20 exit with 1. ctest output showed failure of go_port test with a data race warning and with and failure of GO_pprof with 103 goroutines. command used: ctest -V -R "go_port | GO_pprof" |
Description
This test calls Call() function in a goroutine to fill the queue and calls Destroy() in a goroutine after 2ms for both of them to work concurrently to reproduce the race condition of shutdown with non-empty queue. the problem is as follows when calling Destroy() with non-empty queue toggle chan is closed and so C.metacall_destroy execute and a deadlock occur and block on either Call() waits for <-ret to return a value or Destroy() block on wg.Wait() waiting for workers to finish. the test uses
runtime/pprofto generate a goroutine profile to detect leaked goroutines after test finishes. you can see and verify the profile file using "go tools pprof Goroutine_leaks_report.pprof" command.result of running
go test -v -race -timeout 10s -run TestGoRoutineLeaksshows a data race caught with go thread sanitizergoroutine profile output shows 100 goroutine leaks:
The test was executed with the fix in PR #875 and the deadlock was removed and goroutine profile showed no leaks.
output of
go test -v -race -timeout 10s -run TestGoRoutineLeaksgoroutine profile output: