Closed mymtw closed 4 months ago
maybe you should post simple example code and how use it?
And I use one simple example includes gin.SetMode("test")
and GET
, and then use the following curl
command:
while true
do
curl -v http://localhost:8080/test &
done
But, I don't reproduce the issue.
SetMode()
and other Gin init funcs are not supposed to be called concurrently. They where wrongly designed in origin, by allowing/using a global status. I recommend a simple wrap function for doing gin init router and stuff, with a mutex if you are using Parallel testing.
Changing this behavior would be considered a breaking change, so a proper discussion should be started.
Another option could be to add a mutex to all global functions like SetMode()
, this won't impact performance and should be transparent to all users.
@thinkerou I meant another thing. testing - means test coverage for my code. Here is https://golang.org/pkg/testing/ @javierprovecho thank you, but I'm afraid that adding mutex inside parallel tests will not bring any profit from parallel execution
They where wrongly designed in origin, by allowing/using a global status.
true
@mymtw I don't think so, I meant adding a mutex around SetMode()
, the rest of the test should run fine in parallel 😉
Why can't the ginMode
be read and set atomically? No need to use a mutex here. The changes needed are minimal.
Hi, I'm setting gin mode
And when I'm running my tests in
t.Parallel()
with flag-race
-> I'm gettingdata race warning
:Maybe reason in yr code
ginMode = testCode
?:Your are changing global var from function, it looks like this is not safe. The warning in this context is not dangerous, but it will be better to fix this ASAP