Using channels instead of variables (and a bit of refactoring) removes race conditions from the "language level". There's still a race condition on the level of TCP connections.
It seems to me that this code is better in a sense that communication between goroutines doesn't involve reading and writing from the same variable concurrently.
I see, your problem was with unsynchronized access to the exited boolean, not the structure of the test itself. That makes more sense. I'll take a look at this tomorrow.
Using channels instead of variables (and a bit of refactoring) removes race conditions from the "language level". There's still a race condition on the level of TCP connections.
It seems to me that this code is better in a sense that communication between goroutines doesn't involve reading and writing from the same variable concurrently.