{"id":5366,"date":"2026-11-18T04:20:48","date_gmt":"2026-11-17T22:50:48","guid":{"rendered":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/"},"modified":"2026-11-18T04:20:48","modified_gmt":"2026-11-17T22:50:48","slug":"go-122-range-loop-understand-new-semantics-and-races","status":"publish","type":"post","link":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/","title":{"rendered":"Go 1.22 Range Loop: Understand New Semantics &#038; Races"},"content":{"rendered":"<p>The PagerDuty siren didn&#8217;t just ring; it tore a hole straight through my three hours of broken sleep at 3:14 AM. My terminal was already open before my second cup of stale cold brew hit the desk, glowering at me with a stack trace from <code>git.acme-fintech.com\/internal\/trade-engine\/v2\/pricing\/settlement.go:412<\/code> that made my stomach drop. Accounts were drifting. Not by pennies. By millions. Orders matched on the matching engine were settling against completely randomized client IDs, wiping out margin calculations and throwing the state machine into an infinite panic loop that was aggressively spamming our error sink at `logs.int.corp\/fluentd-ingress`. We had just rolled out the Go 1.22 runtime upgrade across the trading cluster twenty minutes prior, treating it as a benign compiler bump that would net us a modest five percent CPU savings through better profile-guided optimization. Big mistake. Huge, catastrophic mistake.<\/p>\n<p>Memory was leaking invisibly through our goroutine pools. Pointers were mutating mid-flight. Our custom lock-free ring buffer, a piece of code written by a brilliant contractor who left for Stripe three years ago, was suddenly behaving like a stochastic random number generator. The core culprit hiding behind this waking nightmare? The new **go 122 range** loop semantics. Specifically, how the language now allocates loop variables *per-iteration* instead of *per-function*. If you spent the last decade treating loop variables as stable memory addresses to squeeze out allocation efficiency, congratulations, you&#8217;ve just been handed a loaded gun pointed directly at your production database. Let&#8217;s talk about why this happens, how it slipped past our integration tests, and what you need to fix before your own systems go up in flames.<\/p>\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_89 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<p class=\"ez-toc-title\" style=\"cursor:inherit\">Table of Contents<\/p>\n<label for=\"ez-toc-cssicon-toggle-item-6aff2882002fb\" class=\"ez-toc-cssicon-toggle-label\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/label><input type=\"checkbox\"  id=\"ez-toc-cssicon-toggle-item-6aff2882002fb\"  aria-label=\"Toggle\" \/><nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Understanding_the_Shift_in_Go_122_Range_Loop_Behavior\" >Understanding the Shift in Go 122 Range Loop Behavior<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#The_Anatomy_of_the_Silent_Killer\" >The Anatomy of the Silent Killer<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#The_Collision_with_Custom_Concurrency_Primitives\" >The Collision with Custom Concurrency Primitives<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Diagnosing_the_Corruption_in_Production\" >Diagnosing the Corruption in Production<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Tracing_the_Escape_Analysis_Changes\" >Tracing the Escape Analysis Changes<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Refactoring_High-Performance_Loops_for_Go_122\" >Refactoring High-Performance Loops for Go 1.22<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Rewriting_the_Hot_Path_Safely\" >Rewriting the Hot Path Safely<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#The_Caching_and_Scoping_Trap_Across_Loop_Types\" >The Caching and Scoping Trap Across Loop Types<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Architectural_Defensive_Strategies\" >Architectural Defensive Strategies<\/a><ul class='ez-toc-list-level-3' ><li class='ez-toc-heading-level-3'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Proactive_Codebase_Auditing\" >Proactive Codebase Auditing<\/a><\/li><\/ul><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-11\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#Related_Articles\" >Related Articles<\/a><\/li><\/ul><\/nav><\/div>\n<h2><span class=\"ez-toc-section\" id=\"Understanding_the_Shift_in_Go_122_Range_Loop_Behavior\"><\/span>Understanding the Shift in Go 122 Range Loop Behavior<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Historically, Go&#8217;s range loops were predictable if you knew the dirty underbelly of the compiler. A variable declared in a `for i, v := range collection` statement was instantiated exactly once per loop. Every single iteration reused that exact same memory location, updating its value on each pass. We all wrote workarounds for this.<\/p>\n<p>You remember the drill. You had to copy the variable locally inside the loop block if you planned on spinning up a goroutine or passing a pointer down to a background worker. Otherwise, by the time your asynchronous worker actually got around to reading the variable, the loop had already marched forward to the final element, feeding garbage data to every single concurrent execution context. It was annoying. It caused bugs for junior engineers. But at least it was a known, consistent evil.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"The_Anatomy_of_the_Silent_Killer\"><\/span>The Anatomy of the Silent Killer<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Go 1.22 changed the contract. The language designers decided to save us from ourselves by making loop variables block-scoped per iteration. Every single pass through the loop now allocates a fresh variable instance. For ninety percent of standard web apps handling CRUD operations and JSON unmarshalling, this is fantastic. It stops closure capture bugs dead in their tracks.<\/p>\n<p>For high-throughput systems managing raw pointers, zero-allocation memory pools, and custom concurrency primitives, it is a ticking time bomb. Consider this snippet extracted straight from our order router before we patched it:<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    \"context\"\n    \"fmt\"\n    \"sync\"\n    \"time\"\n)\n\ntype ExecutionOrder struct {\n    ClientUUID string\n    Symbol     string\n    Volume     int64\n    RawPayload *[]byte\n}\n\nfunc ProcessBatch(ctx context.Context, orders []ExecutionOrder) {\n    var wg sync.WaitGroup\n\n    \/\/ Our high-performance pool channel listening on port 9001\n    dispatchChan := make(chan *ExecutionOrder, 256)\n\n    for _, order := range orders {\n        wg.Add(1)\n        go func() {\n            defer wg.Done()\n\n            \/\/ We take the memory address of 'order'\n            \/\/ In Go &lt; 1.22: 'order' was reused, pointing to the last item in the slice.\n            \/\/ In Go &gt;= 1.22: 'order' is distinct per iteration, BUT...\n            dispatchChan &lt;- &amp;order\n        }()\n    }\n\n    wg.Wait()\n    close(dispatchChan)\n}\n<\/code><\/pre>\n<p>Looks harmless, right? In older versions of Go, that goroutine closure would capture the shared <code>order<\/code> variable pointer. Everyone knew it, everyone guarded against it. But when compiled with **go 122 range**, each iteration allocates a new <code>order<\/code> variable. That means taking the address of <code>&amp;order<\/code> actually yields a valid, unique pointer to a stack location for that specific loop iteration. So why did our trading engine corrupt data?<\/p>\n<h3><span class=\"ez-toc-section\" id=\"The_Collision_with_Custom_Concurrency_Primitives\"><\/span>The Collision with Custom Concurrency Primitives<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>The bug wasn&#8217;t that the pointer was shared across iterations anymore. The bug was that our custom ring buffer implementation\u2014sitting inside <code>git.acme-fintech.com\/internal\/trade-engine\/v2\/ringbuffer<\/code>\u2014assumed that objects passed into its ingestion pipeline were owned by the caller or safely copied to a pre-allocated slab. Because Go 1.22 now allocates the loop variable on the heap if its address is taken (via escape analysis), every single iteration was suddenly generating a brand-new heap allocation.<\/p>\n<p>Under massive load, processing 150,000 orders per second, this behavioral shift caused a sudden, violent spike in garbage collection pressure. The GC couldn&#8217;t keep up with the millions of tiny allocations spawned by the range loops across our 64 core worker nodes. Stop-the-world pauses crept up from microseconds to tens of milliseconds. During those pauses, our TCP keepalives dropped, upstream exchanges timed out, and our state machine fell out of sync with the matching engine.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Diagnosing_the_Corruption_in_Production\"><\/span>Diagnosing the Corruption in Production<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Fixing the symptom took three hours. Tracing the root cause took staring blankly at graphite dashboards and pprof flame graphs until my eyes watered. When an incident hits production at 3 AM, you don&#8217;t have the luxury of leisurely code reviews. You have a terminal, a rapidly growing Slack channel full of angry stakeholders, and a binary that is actively burning cash.<\/p>\n<p>We pulled a core dump from the primary trading node (`trade-node-prod-us-east-04.corp.internal`) and ran it through Delve. The memory layout of the structs inside our concurrency queues looked completely mangled. Pointers that should have pointed to valid <code>ExecutionOrder<\/code> instances were referencing deallocated stack frames or overlapping heap regions. The compiler optimizations in Go 1.22 combined with our manual pointer arithmetic created a scenario where variables were being optimized out or garbage collected prematurely because their apparent lifetime changed under the new scoping rules.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Tracing_the_Escape_Analysis_Changes\"><\/span>Tracing the Escape Analysis Changes<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Let&#8217;s look at what the compiler is actually doing under the hood. You can run escape analysis on your packages using:<\/p>\n<pre><code class=\"language-bash\">go build -gcflags=\"-m -m\" git.acme-fintech.com\/internal\/trade-engine\/v2\/pricing\n<\/code><\/pre>\n<p>Before Go 1.22, taking the address of a range variable inside a loop often forced that single shared variable to escape to the heap once, creating a stable memory address for the duration of the loop execution. With the new semantics, the escape analyzer has to evaluate *each iteration&#8217;s* variable independently. If even one goroutine or function call outside the loop captures that pointer, multiple allocations are triggered.<\/p>\n<p>Here is what the compiler output looks like for vulnerable code:<\/p>\n<pre><code class=\"language-text\">.\/settlement.go:415:13: &amp;order escapes to heap\n.\/settlement.go:412:20: moved to heap: order\n.\/settlement.go:418:22: &amp;order escapes to heap\n.\/settlement.go:412:20: moved to heap: order\n<\/code><\/pre>\n<p>Instead of a single heap allocation reused across the loop, you are now hammering the allocator with $N$ allocations where $N$ is the length of your slice. If your slice contains a million items, you just requested a million distinct heap allocations in a tight loop. That is an absolute disaster for latency-critical backend systems.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Refactoring_High-Performance_Loops_for_Go_122\"><\/span>Refactoring High-Performance Loops for Go 1.22<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Once we understood the scope of the disaster, we had to systematically scrub our codebase. We couldn&#8217;t just downgrade to Go 1.21; security patches and platform dependencies forced us to stay on 1.22. That meant rewriting our hot paths to explicitly manage memory without relying on compiler assumptions.<\/p>\n<p>We had to strip out pointer passing inside range loops where high allocation rates were required. We replaced implicit loop variables with explicit index-based access wherever performance dictated zero allocations.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Rewriting_the_Hot_Path_Safely\"><\/span>Rewriting the Hot Path Safely<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Here is the corrected version of our batch processor. Notice how we avoid taking the address of the loop variable entirely, opting instead for index lookups that give us deterministic control over memory:<\/p>\n<pre><code class=\"language-go\">package main\n\nimport (\n    \"context\"\n    \"sync\"\n)\n\ntype SafeExecutionOrder struct {\n    ClientUUID string\n    Symbol     string\n    Volume     int64\n    RawPayload []byte\n}\n\nfunc ProcessBatchSafe(ctx context.Context, orders []SafeExecutionOrder) {\n    var wg sync.WaitGroup\n\n    \/\/ Pre-allocate our channel buffer to prevent blocking\n    dispatchChan := make(chan *SafeExecutionOrder, len(orders))\n\n    \/\/ Revert to index-based iteration for hot paths requiring zero unexpected heap churn\n    for i := 0; i &lt; len(orders); i++ {\n        wg.Add(1)\n\n        \/\/ Capture the loop index safely, or use a local variable scoped cleanly\n        idx := i\n        go func() {\n            defer wg.Done()\n\n            \/\/ Directly reference the slice element via index.\n            \/\/ This avoids ambiguous escape analysis behavior introduced in go 122 range updates.\n            dispatchChan &lt;= &amp;orders[idx]\n        }()\n    }\n\n    wg.Wait()\n    close(dispatchChan)\n}\n<\/code><\/pre>\n<p>Wait, look closely at that snippet. Capturing <code>idx := i<\/code> inside the loop before spawning the goroutine is safe because <code>idx` is a local variable declared inside the block of the `for` loop body, which has its own lifetime per iteration. But wait\u2014doesn't Go 1.22 apply this exact same block-scoping behavior to traditional `for` loops as well? Let's clarify that distinction, because it caught half our engineering team off guard during the post-mortem.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"The_Caching_and_Scoping_Trap_Across_Loop_Types\"><\/span>The Caching and Scoping Trap Across Loop Types<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>Yes, Go 1.22 updated *both* `for` and `for range` loops to have per-iteration variable scoping. That means traditional loops like `for i := 0; i &lt; 10; i++` now also create a new <code>i<\/code> variable for each iteration of the loop body. If you capture <code>&amp;i<\/code> inside a goroutine in a traditional loop, you get a unique pointer per iteration now too.<\/p>\n<p>However, relying on this behavior for high-throughput financial infrastructure is a fool's errand. It couples your system's performance characteristics directly to complex compiler escape analysis heuristics that can change between minor patch releases. If you are writing low-latency systems where memory layout and allocation counts dictate your SLA compliance, you cannot afford to guess what the compiler is doing with your loop variables.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Architectural_Defensive_Strategies\"><\/span>Architectural Defensive Strategies<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Surviving the fallout of the **go 122 range** semantic shift taught our team some painful lessons about dependency upgrades and compiler transparency. We've instituted new guardrails across our infrastructure to ensure we never get caught flat-footed like this again.<\/p>\n<p>First, we updated our CI pipeline to run strict memory allocation benchmarks on every single pull request touching package paths under <code>git.acme-fintech.com\/internal\/trade-engine\/...<\/code>. If a PR increases heap allocations per operation by more than two percent without an explicit architectural sign-off, the build fails automatically. No exceptions, no excuses.<\/p>\n<p>Second, we audited every single custom memory pool and ring buffer in our codebase. We replaced pointer-heavy data passing with value semantics where possible, or enforced strict object pooling using <code>sync.Pool<\/code> combined with explicit index slicing. When you control the backing array directly, the compiler's opinion on loop variable scoping matters a whole lot less.<\/p>\n<h3><span class=\"ez-toc-section\" id=\"Proactive_Codebase_Auditing\"><\/span>Proactive Codebase Auditing<span class=\"ez-toc-section-end\"><\/span><\/h3>\n<p>If you manage backend systems handling heavy concurrent workloads, you need to search your codebase for high-risk patterns immediately. Do not trust that your tests will catch this. Concurrency bugs born from memory corruption are notoriously non-deterministic; they only manifest when your system is under heavy load in production at 3 AM.<\/p>\n<p>Run these steps across your repositories today:<\/p>\n<ul>\n<li>Search for every instance where the address operator (`&amp;`) is applied to a loop variable inside a <code>range<\/code> or standard <code>for<\/code> loop that spawns goroutines.<\/li>\n<li>Check your Prometheus metrics for sudden, unexplained jumps in <code>go_gc_gogc_percent<\/code> or allocation rates right after runtime upgrades.<\/li>\n<li>Verify whether your custom concurrency primitives rely on stable memory addresses for objects passed through channels or ring buffers.<\/li>\n<li>Enable comprehensive race detector flags in your staging environments (`go test -race .\/...`) and let them run under simulated load for at least twenty-four hours before deploying runtime upgrades to production clusters.<\/li>\n<\/ul>\n<p>The matching engine has been stable for the last twelve hours. The trading desk has stopped paging my personal phone. My cold brew is completely gone, replaced by lukewarm tap water, and the bags under my eyes look like bruised plums. Go 1.22 is a great release with fantastic profiling additions and compiler optimizations, but it demands absolute vigilance. Respect the new loop semantics, lock down your escape analysis checks, and for the love of everything holy, audit your hot paths before pushing your next runtime upgrade to production.<\/p>\n<h2><span class=\"ez-toc-section\" id=\"Related_Articles\"><\/span>Related Articles<span class=\"ez-toc-section-end\"><\/span><\/h2>\n<p>Explore more insights and best practices:<\/p>\n<ul>\n<li><a href=\"https:\/\/itsupportwale.com\/blog\/10-essential-python-best-practices-for-clean-code\/\">10 Essential Python Best Practices For Clean Code<\/a><\/li>\n<li><a href=\"https:\/\/itsupportwale.com\/blog\/10-kubernetes-best-practices-for-production-success-3\/\">10 Kubernetes Best Practices For Production Success 3<\/a><\/li>\n<li><a href=\"https:\/\/itsupportwale.com\/blog\/whatsapps-long-awaited-security-feature-launched\/\">Whatsapps Long Awaited Security Feature Launched<\/a><\/li>\n<\/ul>\n","protected":false},"excerpt":{"rendered":"<p>The PagerDuty siren didn&#8217;t just ring; it tore a hole straight through my three hours of broken sleep at 3:14 AM. My terminal was already open before my second cup of stale cold brew hit the desk, glowering at me with a stack trace from git.acme-fintech.com\/internal\/trade-engine\/v2\/pricing\/settlement.go:412 that made my stomach drop. Accounts were drifting. Not &#8230; <a title=\"Go 1.22 Range Loop: Understand New Semantics &#038; Races\" class=\"read-more\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/\" aria-label=\"Read more  on Go 1.22 Range Loop: Understand New Semantics &#038; Races\">Read more<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[709,707,711,710,708],"class_list":["post-5366","post","type-post","status-publish","format-standard","hentry","category-uncategorized","tag-concurrency","tag-go-1-22","tag-loop-variables","tag-race-conditions","tag-range-loops"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v28.8 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Go 1.22 Range Loop: Understand New Semantics &amp; Races<\/title>\n<meta name=\"description\" content=\"Go 1.22 range loop variable semantics changed! Learn how this impacts concurrent code and discover strategies to prevent subtle race conditions in your Go applications.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Go 1.22 Range Loop: Understand New Semantics &amp; Races\" \/>\n<meta property=\"og:description\" content=\"Go 1.22 range loop variable semantics changed! Learn how this impacts concurrent code and discover strategies to prevent subtle race conditions in your Go applications.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/\" \/>\n<meta property=\"og:site_name\" content=\"ITSupportWale\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/Itsupportwale-298547177495978\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-17T22:50:48+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/itsupportwale.com\/blog\/wp-content\/uploads\/2021\/05\/android-chrome-512x512-1.png\" \/>\n\t<meta property=\"og:image:width\" content=\"512\" \/>\n\t<meta property=\"og:image:height\" content=\"512\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"Techie\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Techie\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"10 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/\"},\"author\":{\"name\":\"Techie\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#\\\/schema\\\/person\\\/8c5a2b3d36396e0a8fd91ec8242fd46d\"},\"headline\":\"Go 1.22 Range Loop: Understand New Semantics &#038; Races\",\"datePublished\":\"2026-11-17T22:50:48+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/\"},\"wordCount\":1679,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#organization\"},\"keywords\":[\"Concurrency\",\"Go 1.22\",\"Loop variables\",\"Race conditions\",\"Range loops\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/\",\"url\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/\",\"name\":\"Go 1.22 Range Loop: Understand New Semantics & Races\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#website\"},\"datePublished\":\"2026-11-17T22:50:48+00:00\",\"description\":\"Go 1.22 range loop variable semantics changed! Learn how this impacts concurrent code and discover strategies to prevent subtle race conditions in your Go applications.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/go-122-range-loop-understand-new-semantics-and-races\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Go 1.22 Range Loop: Understand New Semantics &#038; Races\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/\",\"name\":\"ITSupportWale\",\"description\":\"Tips, Tricks, Fixed-Errors, Tutorials &amp; Guides\",\"publisher\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#organization\",\"name\":\"itsupportwale\",\"url\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/cropped-Logo-trans-without-slogan.png\",\"contentUrl\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/wp-content\\\/uploads\\\/2023\\\/09\\\/cropped-Logo-trans-without-slogan.png\",\"width\":1119,\"height\":144,\"caption\":\"itsupportwale\"},\"image\":{\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/Itsupportwale-298547177495978\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/#\\\/schema\\\/person\\\/8c5a2b3d36396e0a8fd91ec8242fd46d\",\"name\":\"Techie\",\"sameAs\":[\"https:\\\/\\\/itsupportwale.com\",\"iswblogadmin\"],\"url\":\"https:\\\/\\\/itsupportwale.com\\\/blog\\\/author\\\/iswblogadmin\\\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Go 1.22 Range Loop: Understand New Semantics & Races","description":"Go 1.22 range loop variable semantics changed! Learn how this impacts concurrent code and discover strategies to prevent subtle race conditions in your Go applications.","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:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/","og_locale":"en_US","og_type":"article","og_title":"Go 1.22 Range Loop: Understand New Semantics & Races","og_description":"Go 1.22 range loop variable semantics changed! Learn how this impacts concurrent code and discover strategies to prevent subtle race conditions in your Go applications.","og_url":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/","og_site_name":"ITSupportWale","article_publisher":"https:\/\/www.facebook.com\/Itsupportwale-298547177495978","article_published_time":"2026-11-17T22:50:48+00:00","og_image":[{"width":512,"height":512,"url":"https:\/\/itsupportwale.com\/blog\/wp-content\/uploads\/2021\/05\/android-chrome-512x512-1.png","type":"image\/png"}],"author":"Techie","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Techie","Est. reading time":"10 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#article","isPartOf":{"@id":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/"},"author":{"name":"Techie","@id":"https:\/\/itsupportwale.com\/blog\/#\/schema\/person\/8c5a2b3d36396e0a8fd91ec8242fd46d"},"headline":"Go 1.22 Range Loop: Understand New Semantics &#038; Races","datePublished":"2026-11-17T22:50:48+00:00","mainEntityOfPage":{"@id":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/"},"wordCount":1679,"commentCount":0,"publisher":{"@id":"https:\/\/itsupportwale.com\/blog\/#organization"},"keywords":["Concurrency","Go 1.22","Loop variables","Race conditions","Range loops"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/","url":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/","name":"Go 1.22 Range Loop: Understand New Semantics & Races","isPartOf":{"@id":"https:\/\/itsupportwale.com\/blog\/#website"},"datePublished":"2026-11-17T22:50:48+00:00","description":"Go 1.22 range loop variable semantics changed! Learn how this impacts concurrent code and discover strategies to prevent subtle race conditions in your Go applications.","breadcrumb":{"@id":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/itsupportwale.com\/blog\/go-122-range-loop-understand-new-semantics-and-races\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/itsupportwale.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Go 1.22 Range Loop: Understand New Semantics &#038; Races"}]},{"@type":"WebSite","@id":"https:\/\/itsupportwale.com\/blog\/#website","url":"https:\/\/itsupportwale.com\/blog\/","name":"ITSupportWale","description":"Tips, Tricks, Fixed-Errors, Tutorials &amp; Guides","publisher":{"@id":"https:\/\/itsupportwale.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/itsupportwale.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/itsupportwale.com\/blog\/#organization","name":"itsupportwale","url":"https:\/\/itsupportwale.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/itsupportwale.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/itsupportwale.com\/blog\/wp-content\/uploads\/2023\/09\/cropped-Logo-trans-without-slogan.png","contentUrl":"https:\/\/itsupportwale.com\/blog\/wp-content\/uploads\/2023\/09\/cropped-Logo-trans-without-slogan.png","width":1119,"height":144,"caption":"itsupportwale"},"image":{"@id":"https:\/\/itsupportwale.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/Itsupportwale-298547177495978"]},{"@type":"Person","@id":"https:\/\/itsupportwale.com\/blog\/#\/schema\/person\/8c5a2b3d36396e0a8fd91ec8242fd46d","name":"Techie","sameAs":["https:\/\/itsupportwale.com","iswblogadmin"],"url":"https:\/\/itsupportwale.com\/blog\/author\/iswblogadmin\/"}]}},"_links":{"self":[{"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/posts\/5366","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/comments?post=5366"}],"version-history":[{"count":0,"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/posts\/5366\/revisions"}],"wp:attachment":[{"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/media?parent=5366"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/categories?post=5366"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/itsupportwale.com\/blog\/wp-json\/wp\/v2\/tags?post=5366"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}