Skip to content

fix: ExchangeSession.UnmarshalJSON infinite recursion#2

Closed
rs-assistant wants to merge 1 commit into
mainfrom
fix/unmarshal-json-recursion
Closed

fix: ExchangeSession.UnmarshalJSON infinite recursion#2
rs-assistant wants to merge 1 commit into
mainfrom
fix/unmarshal-json-recursion

Conversation

@rs-assistant
Copy link
Copy Markdown
Collaborator

Summary

  • ExchangeSession.UnmarshalJSON calls json.Unmarshal(data, session) which dispatches back to UnmarshalJSON, causing infinite recursion and a fatal stack overflow at runtime.
  • Fix: use a type alias (exchangeSessionAlias) to break the recursion chain, so json.Unmarshal uses the default decoder.

Root cause

Commit 844601fe4 introduced the UnmarshalJSON method. The second unmarshal call passes session (a *ExchangeSession) directly, which triggers the custom UnmarshalJSON again — infinite loop.

// Before (bug):
json.Unmarshal(data, session)  // calls UnmarshalJSON → infinite recursion

// After (fix):
type exchangeSessionAlias ExchangeSession
json.Unmarshal(data, (*exchangeSessionAlias)(session))  // uses default decoder

How it was found

The optimizer (bbgo optimize) crashes with fatal error: stack overflow when parsing YAML configs containing exchange session definitions.

Test plan

  • Verified bbgo-slim optimize completes without stack overflow after fix
  • Verified bbgo-slim backtest runs correctly with the fix

🤖 Generated with Claude Code

ExchangeSession.UnmarshalJSON calls json.Unmarshal(data, session),
which dispatches back to UnmarshalJSON, causing infinite recursion
and a fatal stack overflow at runtime.

Use a type alias to break the recursion so json.Unmarshal uses the
default decoder instead of calling UnmarshalJSON again.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@rs-assistant
Copy link
Copy Markdown
Collaborator Author

Retargeting to upstream c9s/bbgo.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant