Repository navigation
fix(sf-fin): load Salesforce modules once for parallel calls - #984
Merged
Merged
Conversation
Two sf_fin salesforce calls in one parallel batch (readiness and observe) made the second fail with "Cannot access 'DEFAULT_CONNECTION_TIMEOUT_MS' before initialization". SF Fin imports the Salesforce connection module lazily so boot stays free of the SDK. Pi loads extensions through jiti, where a second import() of a module still being evaluated returns it part-way through, so its first call read a constant that was not initialized yet. Each lazy loader now shares one import promise across callers and drops it after a failed load so the next call retries. The test loads the module through jiti with Pi's loader options and calls the loaders concurrently; it reproduced the exact error before the fix.
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.
When two
sf_finsalesforce calls run in one parallel batch (for example readiness and observe), the second one fails:Cause
SF Fin imports the Salesforce connection module lazily so Pi's boot stays free of the Salesforce SDK. Pi loads extensions through jiti. Under jiti, a second
import()of a module that is still being evaluated returns the module part-way through, so the second caller's first call read a constant that was not initialized yet. Native Node ESM does not behave this way, so this happens only under Pi's loader.Fix
lib/lazy-imports.ts: each lazy loader shares one import promise across callers and drops it after a failed load, so the next call retries.service.tsuses these loaders for the connection, org, and token-transfer modules. The boot path is unchanged (check-boot-pathpasses).Proof
lazy-imports.test.tsloads the module through jiti with Pi's loader options and calls the loaders concurrently. It reproduced the exact error before the fix and passes after it. It uses an org alias that does not exist, so it never touches an org.npm run validate:cipasses.