Skip to content

fix(realunit): defer Config read in pricing service to avoid bootstrap crash#3832

Merged
TaprootFreak merged 1 commit into
developfrom
fix/realunit-lazy-token-blockchain
Jun 8, 2026
Merged

fix(realunit): defer Config read in pricing service to avoid bootstrap crash#3832
TaprootFreak merged 1 commit into
developfrom
fix/realunit-lazy-token-blockchain

Conversation

@TaprootFreak

Copy link
Copy Markdown
Collaborator

Summary

PricingRealUnitService read Config.environment in a class field initializer. Because of a circular import between this service and src/config/config, the Config singleton is undefined at construction time, so NestJS DI threw:

TypeError: Cannot read properties of undefined (reading 'environment')
  at new PricingRealUnitService (.../pricing-realunit.service.ts)

This happened during DI instantiation, so the whole API failed to bootstrap (crash loop, all health endpoints down on DEV).

Root cause

The recently added field:

private readonly tokenBlockchain = [Environment.DEV, Environment.LOC].includes(Config.environment)
  ? Blockchain.SEPOLIA : Blockchain.ETHEREUM;

Environment (an enum) resolves fine, but the Config value is assigned later and is still undefined when the field initializer runs under the import cycle.

Fix

Convert tokenBlockchain into a lazy getter so the Config read is deferred to runtime, after the module graph is fully initialized. The value is only consumed at runtime (getLastKnownPrice), so behavior is unchanged.

Local checks (npm ci, all green)

  • lint ✅ · format:check ✅ · build ✅ · test (75 suites, 1009 tests) ✅ · npm audit --audit-level=critical

Test plan

  • Targeted spec pricing-realunit.service.spec.ts passes (4/4)
  • Full unit-test suite green

…p crash

PricingRealUnitService read Config.environment in a class field initializer.
Because of a circular import, Config is undefined at construction time, so
NestJS DI threw "Cannot read properties of undefined (reading 'environment')"
and the whole API failed to bootstrap (crash loop, all health checks down).

Convert the field into a lazy getter so Config is read at runtime, after the
module graph is fully initialized.
@TaprootFreak TaprootFreak marked this pull request as ready for review June 8, 2026 08:42
@TaprootFreak TaprootFreak requested a review from davidleomay as a code owner June 8, 2026 08:42
@TaprootFreak TaprootFreak merged commit a0d38ac into develop Jun 8, 2026
6 checks passed
@TaprootFreak TaprootFreak deleted the fix/realunit-lazy-token-blockchain branch June 8, 2026 08:42
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