Recipe 55 | Using the Race Detector |
Task
Aditi from operations comes over and says, “We think that the metrics your server is showing are wrong. I hit an endpoint 1,000 times and saw only 987 in the metric.”
You ask her to create an issue and assign it to you. Next morning, the issue waits for you with high priority, and you start working on it.
Solution
You start by looking at the code, and then you create a simple program that mimics what the code does.
You create a single metric, called callCount:
| var ( |
| callCount int |
| ) |
You then create a simple handler that increments the counter and sleeps for a random time:
| func handler(w http.ResponseWriter, r *http.Request) { |
| callCount++ ... |
Get Effective Go Recipes now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.