A colleague wrote a concurrent DNS cache. It seems to work locally but behaves unpredictably in production — sometimes it resolves all domains, sometimes only a few, and occasionally it crashes entirely.
Your job is to find and fix all concurrency bugs.
Run the program:
go run .Run the tests:
go test -race -count=1 ./...- Do not change the test file
- All tests must pass with
-race - The program must always resolve all domains
- There are 4 distinct concurrency issues in
main.go - The race detector will help you find most of them
- One of the bugs is subtle: it only shows up when an entry is read and removed by concurrent goroutines
A reference solution lives in solution/. Try the exercise
first — peeking spoils it.