fix(realunit): defer Config read in pricing service to avoid bootstrap crash#3832
Merged
Merged
Conversation
…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.
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
PricingRealUnitServicereadConfig.environmentin a class field initializer. Because of a circular import between this service andsrc/config/config, theConfigsingleton isundefinedat construction time, so NestJS DI threw: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:
Environment(an enum) resolves fine, but theConfigvalue is assigned later and is stillundefinedwhen the field initializer runs under the import cycle.Fix
Convert
tokenBlockchaininto a lazy getter so theConfigread 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
pricing-realunit.service.spec.tspasses (4/4)