{"id":429,"date":"2026-05-22T09:00:00","date_gmt":"2026-05-22T03:30:00","guid":{"rendered":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/"},"modified":"2026-05-22T09:00:00","modified_gmt":"2026-05-22T03:30:00","slug":"go-race-detector-data-races","status":"publish","type":"post","link":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/","title":{"rendered":"Go Race Detector: Find and Fix Data Races"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">The Go race detector is a built-in tool that finds data races. These are some of the hardest bugs in concurrent code. In this post, you will learn what a data race is and how to switch the detector on. Then we will fix a broken counter in two different ways and compare the fixes.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This lesson builds on <a href=\"https:\/\/smitabharat.com\/blog\/go-goroutines-beginners-guide\/\">Go goroutines for beginners<\/a> and <a href=\"https:\/\/smitabharat.com\/blog\/go-sync-package-waitgroup-mutex\/\">Go sync package with WaitGroup and Mutex<\/a>. We also use ideas from <a href=\"https:\/\/smitabharat.com\/blog\/go-httptest-handlers\/\">Go httptest for testing handlers<\/a>, because the detector works well inside tests. So if goroutines are new to you, read those lessons first.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">What Is the Go Race Detector?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">A data race happens when two goroutines touch the same variable at the same time. At least one of them must be writing. In short, the Go race detector watches your running program and reports every such moment. Because it is part of the Go toolchain, you do not install anything.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Think of two people editing one paper form at the same moment. One crosses out a number while the other writes a new one. As a result, the final form may show something neither person meant. Similarly, two goroutines can overwrite each other&#8217;s work, and the result changes from run to run.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Races are dangerous because the program often looks fine. For example, it may pass every test on your laptop and then fail only on a busy server. As a result, you need a tool, not just careful reading. Fortunately, the Go race detector makes this check almost automatic.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Why the Go Race Detector Matters<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Concurrency is one of Go&#8217;s best features, but it also makes bugs harder to see. So here is what the Go race detector gives you.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Proof, not guesses<\/strong>: it shows the exact lines that read and write the shared value.<\/li>\n\n\n\n<li><strong>Early warnings<\/strong>: it finds races in tests, long before users see them.<\/li>\n\n\n\n<li><strong>Hidden bugs made visible<\/strong>: it catches races even when the final output looks correct.<\/li>\n\n\n\n<li><strong>Safer refactoring<\/strong>: you can change concurrent code and re-check it in seconds.<\/li>\n\n\n\n<li><strong>Team trust<\/strong>: a clean race test run builds confidence before a release.<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Because of this, the Go team recommends running tests with <code>-race<\/code> as a normal habit. In fact, a few extra seconds in your test run can save days of debugging later.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">How the Go Race Detector Works<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">You turn on the Go race detector with the <code>-race<\/code> flag on <code>go run<\/code>, <code>go test<\/code> or <code>go build<\/code>. After that, the compiler adds extra checks around every memory access. While the program runs, the detector records which goroutine touched which address and when. Finally, if two accesses clash without a proper synchronisation step between them, it prints a report.<\/p>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1-1024x640.png\" alt=\"Go Race Detector diagram showing two goroutines writing one counter and the race report\" class=\"wp-image-406\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-1-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">Two goroutines write the same counter with no lock between them. The race detector records both writes and prints a report with the two stack traces.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">However, the detector only reports races that actually happen during the run. In other words, it cannot see code that never executes. So good tests matter just as much as the flag.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">What a Race Report Contains<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">A report has a few clear parts, so the table below explains each one.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Report part<\/th><th>What it tells you<\/th><\/tr><\/thead><tbody><tr><td><code>WARNING: DATA RACE<\/code><\/td><td>A race was found<\/td><\/tr><tr><td><code>Read at<\/code> or <code>Write at<\/code><\/td><td>The memory address and the goroutine<\/td><\/tr><tr><td><code>Previous write at<\/code><\/td><td>The earlier access that clashed<\/td><\/tr><tr><td><code>Goroutine ... created at<\/code><\/td><td>The line that started each goroutine<\/td><\/tr><tr><td><code>Found N data race(s)<\/code><\/td><td>The total, printed at exit<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">Also, a program with a detected race exits with status 66. As a result, CI tools can stop the build.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">The Cost of the Detector<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">The detector is not free. For example, programs usually run several times slower and use more memory. Therefore, use it in tests and staging. On the other hand, avoid shipping a <code>-race<\/code> build to production unless you have a good reason.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Race Detector: Mutex vs Atomic<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">There are two common ways to fix a simple counter race. Both are correct, but they fit different jobs, as the table below shows. Either way, the Go race detector will confirm that the fix works.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Feature<\/th><th><code>sync.Mutex<\/code><\/th><th><code>sync\/atomic<\/code><\/th><\/tr><\/thead><tbody><tr><td>Protects<\/td><td>Any block of code<\/td><td>One number or pointer<\/td><\/tr><tr><td>Speed<\/td><td>Fast<\/td><td>Fastest for simple counters<\/td><\/tr><tr><td>Easy to misuse<\/td><td>A little, if you forget to release it<\/td><td>Less, but the API is small<\/td><\/tr><tr><td>Several variables at once<\/td><td>Yes<\/td><td>No<\/td><\/tr><tr><td>Best for<\/td><td>Maps, structs, multi-step updates<\/td><td>Counters and flags<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<figure class=\"wp-block-image aligncenter size-large\"><a href=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2.png\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"640\" src=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2-1024x640.png\" alt=\"Go Race Detector diagram comparing a mutex with an atomic counter\" class=\"wp-image-407\" srcset=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2-1024x640.png 1024w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2-300x188.png 300w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2-768x480.png 768w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2-1536x960.png 1536w, https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-diagram-2-2048x1280.png 2048w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/a><figcaption class=\"wp-element-caption\">A mutex lets only one goroutine run a protected block at a time, while an atomic operation updates one value in a single safe step.<\/figcaption><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">So when should you use which? Use an atomic for a single counter or flag. On the other hand, use a mutex when you update several fields or a map together.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Go Race Detector Hands-On: Fix a Broken Counter<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">Now let&#8217;s see a real race and fix it. We start 100 goroutines. Each one adds 1 to the same counter 1000 times, so the right answer is 100000.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 1: The Broken Version<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, here is the broken code. Later, we add a mutex fix and an atomic fix in the same file.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>func main() {\n\t\/\/ 1. Broken: plain counter shared by 100 goroutines.\n\tbroken := 0\n\tvar wg sync.WaitGroup\n\tfor i := 0; i &lt; 100; i++ {\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tfor j := 0; j &lt; 1000; j++ {\n\t\t\t\tbroken++\n\t\t\t}\n\t\t}()\n\t}\n\twg.Wait()\n\tfmt.Println(\"broken:\", broken)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">The line <code>broken++<\/code> looks like one step. In reality, it reads the value, adds one and writes it back. So two goroutines can read the same old value. As a result, one update gets lost.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 2: Fix It with a Mutex<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Next, we wrap the increment in a lock. Because only one goroutine can hold the lock at a time, no update is lost.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tvar mu sync.Mutex\n\tlocked := 0\n\tfor i := 0; i &lt; 100; i++ {\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tfor j := 0; j &lt; 1000; j++ {\n\t\t\t\tmu.Lock()\n\t\t\t\tlocked++\n\t\t\t\tmu.Unlock()\n\t\t\t}\n\t\t}()\n\t}\n\twg.Wait()\n\tfmt.Println(\"mutex:\", locked)<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 3: Fix It with an Atomic Counter<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, we use <code>atomic.Int64<\/code>. It updates the number in one safe step, so it needs no lock.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\tvar atom atomic.Int64\n\tfor i := 0; i &lt; 100; i++ {\n\t\twg.Add(1)\n\t\tgo func() {\n\t\t\tdefer wg.Done()\n\t\t\tfor j := 0; j &lt; 1000; j++ {\n\t\t\t\tatom.Add(1)\n\t\t\t}\n\t\t}()\n\t}\n\twg.Wait()\n\tfmt.Println(\"atomic:\", atom.Load())\n}<\/code><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\">Step 4: Run It with and without -race<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now run <code>go run .<\/code> and look at the output. The broken counter loses updates, and the exact number changes on every run. For example, our first run printed the numbers below.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>broken: 85855\nmutex: 100000\natomic: 100000<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Sometimes the broken line even prints 100000 by luck, which is why races are so sneaky. Then build the program with <code>go build -race<\/code> and run it. This time, the detector reports the problem every time. We shortened the file paths here.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>==================\nWARNING: DATA RACE\nRead at 0x00c000112078 by goroutine 15:\n  main.main.func1()\n      main.go:18 +0x99\n\nPrevious write at 0x00c000112078 by goroutine 7:\n  main.main.func1()\n      main.go:18 +0xab\n\nGoroutine 15 (running) created at:\n  main.main()\n      main.go:15 +0x99\n==================\nbroken: 69298\nmutex: 100000\natomic: 100000\nFound 2 data race(s)<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Let&#8217;s read the report. First, line 18 is <code>broken++<\/code>, and both the read and the write happen there. Also, the report says which goroutines clashed and where they were created. Finally, the mutex and atomic versions never appear in the report, so they are safe.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Step 5: Use the Race Detector in Tests<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">In real projects, you run the Go race detector with your tests. Type <code>go test -race .\/...<\/code> and every race that your tests trigger will fail the run. Then add this command to your CI pipeline. As a result, races will stop reaching production.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Common Mistakes with the Go Race Detector<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>Trusting a passing run<\/strong>: a clean run without <code>-race<\/code> proves nothing. So run the Go race detector regularly.<\/li>\n\n\n\n<li><strong>Ignoring the report<\/strong>: some people mark races as &#8220;harmless&#8221;. However, a race can corrupt data in practice, so fix every one.<\/li>\n\n\n\n<li><strong>Protecting only the writes<\/strong>: reads need the lock as well. Otherwise, a reader can see half-updated data.<\/li>\n\n\n\n<li><strong>Concurrent map writes<\/strong>: a plain map is not safe for many goroutines. In fact, Go may crash with <code>fatal error: concurrent map writes<\/code>, so guard maps with a mutex.<\/li>\n\n\n\n<li><strong>Copying a mutex<\/strong>: a copied mutex is a different lock, so it protects nothing. Pass pointers instead, and run <code>go vet<\/code> to catch this.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Best Practices for the Go Race Detector<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>**Run <code>go test -race .\/...<\/code> in CI**, because it catches races on every commit.<\/li>\n\n\n\n<li><strong>Share memory by communicating<\/strong>, since channels often remove the need for locks. A well-built pipeline needs very few mutexes.<\/li>\n\n\n\n<li><strong>Keep locks short<\/strong>, which reduces waiting and lowers the risk of deadlocks.<\/li>\n\n\n\n<li>**Use <code>defer<\/code> right after taking a lock**, because it releases the lock even when the code panics.<\/li>\n\n\n\n<li><strong>Write concurrent tests<\/strong>, since a race can only appear when goroutines really overlap.<\/li>\n\n\n\n<li><strong>Prefer atomics for simple counters<\/strong>, because they are small and fast.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Practice Task<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">To practise the Go race detector, write a program that starts 50 goroutines and appends numbers to one shared slice. First, run it with <code>-race<\/code> and read the report. Then fix it in two ways, once with a mutex and once with a channel.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Hint: with a channel, let each goroutine send its number, and use one goroutine to do all the appends. Then compare how the two fixes read.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Official Resources<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">These pages explain the detector, the memory model and the sync packages in detail.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><a href=\"https:\/\/go.dev\/doc\/articles\/race_detector\">Data Race Detector guide<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/go.dev\/ref\/mem\">The Go Memory Model<\/a><\/li>\n\n\n\n<li><a href=\"https:\/\/pkg.go.dev\/sync\/atomic\">sync\/atomic package documentation<\/a><\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">Quick Recap<\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>A data race means two goroutines touch one variable at once, and one of them writes.<\/li>\n\n\n\n<li>The Go race detector finds races when you add the <code>-race<\/code> flag.<\/li>\n\n\n\n<li>Its report shows both accesses and where each goroutine started.<\/li>\n\n\n\n<li>Fix races with a mutex, an atomic value or a channel.<\/li>\n\n\n\n<li>Run <code>go test -race .\/...<\/code> in CI, and avoid <code>-race<\/code> builds in production.<\/li>\n\n\n\n<li>A clean normal run does not prove that your code is race free.<\/li>\n<\/ul>\n\n\n\n<h2 class=\"wp-block-heading\">What&#8217;s Next?<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">By now, you can find and fix races. However, the best fix is often a design with no shared memory at all. So next, we will use goroutines and channels together to build a clean pipeline, with fan-out and fan-in.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Next up: <a href=\"https:\/\/smitabharat.com\/blog\/go-pipeline-fan-out-fan-in\/\">Go pipeline pattern with fan-out and fan-in<\/a><\/p>\n\n","protected":false},"excerpt":{"rendered":"<p>The Go race detector is a built-in tool that finds data races. These are some of the hardest bugs in concurrent code. In this&hellip;<\/p>\n","protected":false},"author":1,"featured_media":405,"comment_status":"","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_swapz_level":"","_swapz_series_part":0,"_swapz_hide_toc":false,"_swapz_hide_featured":false,"_swapz_description":"","footnotes":""},"categories":[15],"tags":[80,79,11],"swapz_series":[],"class_list":["post-429","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-go-lang","tag-advanced","tag-go-concurrency","tag-go-lang"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.9 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go Race Detector: Find and Fix Data Races<\/title>\n<meta name=\"description\" content=\"Learn the Go race detector step by step: what a data race is, how to use the race flag, read reports and fix races with mutex or atomic.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go Race Detector: Find and Fix Data Races\" \/>\n<meta property=\"og:description\" content=\"Learn the Go race detector step by step: what a data race is, how to use the race flag, read reports and fix races with mutex or atomic.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/\" \/>\n<meta property=\"og:site_name\" content=\"Smita Bharat - Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-05-22T03:30:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-featured.png\" \/>\n\t<meta property=\"og:image:width\" content=\"2400\" \/>\n\t<meta property=\"og:image:height\" content=\"1260\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Smita\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Smita\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/\"},\"author\":{\"name\":\"Smita\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"headline\":\"Go Race Detector: Find and Fix Data Races\",\"datePublished\":\"2026-05-22T03:30:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/\"},\"wordCount\":1497,\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-race-detector-data-races-featured.png\",\"keywords\":[\"Advanced\",\"Go Concurrency\",\"Go Lang\"],\"articleSection\":[\"Go Lang\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/\",\"name\":\"Go Race Detector: Find and Fix Data Races\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-race-detector-data-races-featured.png\",\"datePublished\":\"2026-05-22T03:30:00+00:00\",\"description\":\"Learn the Go race detector step by step: what a data race is, how to use the race flag, read reports and fix races with mutex or atomic.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#primaryimage\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-race-detector-data-races-featured.png\",\"contentUrl\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/10\\\/go-race-detector-data-races-featured.png\",\"width\":2400,\"height\":1260,\"caption\":\"Go Race Detector featured image: turn on race mode, read the report and fix the race\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/go-race-detector-data-races\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go Race Detector: Find and Fix Data Races\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/\",\"name\":\"Smita Bharat Blog\",\"description\":\"Golang &amp; Backend Development Tutorials and Interview Questions\",\"publisher\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\"},\"alternateName\":\"Smita Bharat\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":[\"Person\",\"Organization\"],\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/27a1b1067d396703215c54acedbfd339\",\"name\":\"Smita\",\"logo\":{\"@id\":\"https:\\\/\\\/smitabharat.com\\\/blog\\\/#\\\/schema\\\/person\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/smitabharat.com\\\/blog\"]}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go Race Detector: Find and Fix Data Races","description":"Learn the Go race detector step by step: what a data race is, how to use the race flag, read reports and fix races with mutex or atomic.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/","og_locale":"en_US","og_type":"article","og_title":"Go Race Detector: Find and Fix Data Races","og_description":"Learn the Go race detector step by step: what a data race is, how to use the race flag, read reports and fix races with mutex or atomic.","og_url":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/","og_site_name":"Smita Bharat - Blog","article_published_time":"2026-05-22T03:30:00+00:00","og_image":[{"width":2400,"height":1260,"url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-featured.png","type":"image\/png"}],"author":"Smita","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Smita","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#article","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/"},"author":{"name":"Smita","@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"headline":"Go Race Detector: Find and Fix Data Races","datePublished":"2026-05-22T03:30:00+00:00","mainEntityOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/"},"wordCount":1497,"publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-featured.png","keywords":["Advanced","Go Concurrency","Go Lang"],"articleSection":["Go Lang"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/","url":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/","name":"Go Race Detector: Find and Fix Data Races","isPartOf":{"@id":"https:\/\/smitabharat.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#primaryimage"},"image":{"@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#primaryimage"},"thumbnailUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-featured.png","datePublished":"2026-05-22T03:30:00+00:00","description":"Learn the Go race detector step by step: what a data race is, how to use the race flag, read reports and fix races with mutex or atomic.","breadcrumb":{"@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#primaryimage","url":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-featured.png","contentUrl":"https:\/\/smitabharat.com\/blog\/wp-content\/uploads\/2026\/10\/go-race-detector-data-races-featured.png","width":2400,"height":1260,"caption":"Go Race Detector featured image: turn on race mode, read the report and fix the race"},{"@type":"BreadcrumbList","@id":"https:\/\/smitabharat.com\/blog\/go-race-detector-data-races\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/smitabharat.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go Race Detector: Find and Fix Data Races"}]},{"@type":"WebSite","@id":"https:\/\/smitabharat.com\/blog\/#website","url":"https:\/\/smitabharat.com\/blog\/","name":"Smita Bharat Blog","description":"Golang &amp; Backend Development Tutorials and Interview Questions","publisher":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339"},"alternateName":"Smita Bharat","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/smitabharat.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":["Person","Organization"],"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/27a1b1067d396703215c54acedbfd339","name":"Smita","logo":{"@id":"https:\/\/smitabharat.com\/blog\/#\/schema\/person\/image\/"},"sameAs":["https:\/\/smitabharat.com\/blog"]}]}},"_links":{"self":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/429","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/comments?post=429"}],"version-history":[{"count":0,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/posts\/429\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media\/405"}],"wp:attachment":[{"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/media?parent=429"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/categories?post=429"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/tags?post=429"},{"taxonomy":"swapz_series","embeddable":true,"href":"https:\/\/smitabharat.com\/blog\/wp-json\/wp\/v2\/swapz_series?post=429"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}