Uh oh!
There was an error while loading. Please reload this page.
fix: unbounded DictionarySlim growth when creating many IHandlebars instances (issue #541) - #625
Merged
Merged
Conversation
…keys (issue #541) DictionarySlim.AddOrReplace was missing a `return` after updating the value for an existing key, causing it to always fall through to AddValue and insert a duplicate entry. Under sustained load (e.g. many IHandlebars instances each calling RegisterHelper with the same name), the dictionary grew without bound and eventually threw OutOfMemoryException from Resize. Added two regression tests in IssueTests: one verifying the helpers count stays at 1 after 100 repeated registrations of the same name, and one confirming correct behaviour when creating 1000 IHandlebars instances. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
rexm
enabled auto-merge
June 20, 2026 02:05
Uh oh!
There was an error while loading. Please reload this page.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for freeto join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.



Fixes#541
Root Cause
DictionarySlim<TKey, TValue, TComparer>.AddOrReplacewas missing areturnstatement after updating the value for an existing key. This meant the method always fell through toAddValue, unconditionally inserting a new (duplicate) entry for every call — even when the key was already present.Under sustained load — e.g. a DI-resolved service creating a new
Handlebars.Create()instance and callingRegisterHelperon each request — the internal dictionary grew without bound, eventually exhausting memory and throwingOutOfMemoryExceptionfromDictionarySlim.Resize.Fix
Added the missing
returnafter the value-update path inAddOrReplace(one-line change insource/Handlebars/Collections/DictionarySlim.cs):Tests
Two new regression tests added to
IssueTests.cs:RegisterHelperRepeatedly_ShouldNotCauseUnboundedGrowth— creates 1 000IHandlebarsinstances, each registering the same helper name twice, and compiles/runs the template to verify correct output.RegisterHelper_SameNameRepeatedly_ShouldNotGrowHelpersCount— registers the same helper name 100 times on a single instance and assertsConfiguration.Helpershas exactly 1 entry (would be 100 with the bug).All 1 748 existing tests continue to pass.
🤖 Generated with Claude Code