Homework 0 forum

Potential Race Condition in TestCli

 
Picture of Yuchen Qian
Potential Race Condition in TestCli
by Yuchen Qian - Friday, 25 September 2020, 16:14
 

There is a potential race condition inside TestCli: when the http server hasn't started with the async call, but the sendMsg tries to contact the server already. A quick ugly fix would be to wait a few milliseconds in the client, but a potential better fix would be to have some synchronization (like the ready channel). Should we take this race into consideration when we're implementing the sendMsg in cli/cli.go? 

Thanks for your time and have a nice day :)

Picture of Cristina Basescu
Re: Potential Race Condition in TestCli
by Cristina Basescu - Friday, 25 September 2020, 16:26
 

Thanks for reporting, you're totally right. I couldn't replicate the error, but we're aware that it could happen. In the client test (and just *that* test), it would be better if the test waited for a bit after starting the server in a separate go thread. Thus, if you fail the test and suspect that's the cause, (the server isn't ready to receive messages, so you get an error), please add a sleep immediately after the go routine.

In the interest of not changing the tests, we won't push a change. But we will take the issue into account when grading.

Did you observe this error when testing locally or on gitlab?


Picture of Yuchen Qian
Re: Potential Race Condition in TestCli
by Yuchen Qian - Friday, 25 September 2020, 17:31
 

Yes, I did observe this behaviour both locally and on gitlab... Thanks :)