fix(errors): prevent infinite recursion in (*Error).As causing 100% CPU#459
Merged
freemans13 merged 2 commits intobsv-blockchain:mainfrom Feb 5, 2026
Merged
Conversation
Contributor
|
🤖 Claude Code Review Status: Complete No issues found. The fix correctly prevents infinite recursion in Analysis:
|
|
liam
approved these changes
Feb 5, 2026
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.



Summary
errors.(*Error).AsmethodProblem
During catchup sync, teranode was getting stuck at 100% CPU on all cores. CPU profiling showed 99% of CPU was spent in
errors.(*Error).As:The call chain was:
Root Cause
The
(*Error).Asmethod was manually traversing wrapped errors by calling.As(target)on them:When the wrapped error was also an
*Error, this created infinite recursion because:errors.Ascallse1.As(target)e1.As(target)manually callse1.wrappedErr.As(target)=e2.As(target)e2.As(target)manually callse2.wrappedErr.As(target)= ...errors.Asalso traverses viaUnwrap(), causing double/exponential traversalAdditionally, the
reflect.ValueOf(err).IsNil()check was expensive (5.78% of CPU).Fix
Skip manual traversal when the wrapped error is
*Error- Go'serrors.Ashandles this automatically viaUnwrap():This also removes the expensive
reflect.ValueOf(err).IsNil()call.Test plan
🤖 Generated with Claude Code