Repository navigation
Conversation
fxamacker
marked this pull request as draft
September 24, 2026 02:51
fxamacker
force-pushed
the
fxamacker/release-2.9-fix-encodiong-with-self-reference-type
branch
2 times, most recently
from
October 1, 2026 00:33
3b02113 to
e331380
Compare
Not affected: user apps that don't encode a Go type that refers to itself through a cycle containing an array, slice, or map element without a struct in the cycle (e.g. type T map[string]T). This commit handles self-referencing types by storing newly created encoding functions in a temporary cache during type traversal. The temporary cache is created per getEncodeFunc() cache miss. When a type is encountered during traversal, the temporary cache is checked first, followed by the regular cache, and then getEncodeFuncInternal() is called. If a type is encountered recursively during traversal, a closure function that indirectly calls the type's encoding function is returned. After traversal is completed, all types in the temporary cache are added to the regular cache. Previously, traversing self-referencing types resulted in an unrecoverable stack overflow.
fxamacker
force-pushed
the
fxamacker/release-2.9-fix-encodiong-with-self-reference-type
branch
from
October 1, 2026 01:09
e331380 to
3461c94
Compare
fxamacker
marked this pull request as ready for review
October 1, 2026 13:17
x448
approved these changes
Oct 1, 2026
fxamacker
deleted the
fxamacker/release-2.9-fix-encodiong-with-self-reference-type
branch
October 1, 2026 23:32
fxamacker
added a commit
that referenced
this pull request
Oct 2, 2026
Port #833 from release-2.9 to master
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 free
to 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.
Not affected: user apps that don't encode a Go type that refers to itself through a cycle containing an array, slice, or map element without a struct in the cycle.
This PR handles self-referencing types by storing newly created encoding functions in a temporary cache during type traversal. The temporary cache is created per
getEncodeFunc()cache miss. When a type is encountered during traversal, the temporary cache is checked first, followed by the regular cache, and thengetEncodeFuncInternal()is called. If a type is encountered recursively during traversal, a closure function that indirectly calls the type's encoding function is returned. After traversal is completed, all types in the temporary cache are added to the regular cache.Previously, traversing self-referencing types resulted in an unrecoverable stack overflow.