fix: prevent infinite loop during storage initialization (v6.0.1)
CRITICAL FIX for production blocker in v6.0.0: Root Cause: - BaseStorage.init() set isInitialized = true at the END of initialization - If any code during init called ensureInitialized(), it triggered init() recursively - This caused infinite loop on fresh workspace initialization Fix: - Set isInitialized = true at START of BaseStorage.init() - Wrap in try/catch to reset flag on error - Prevents recursive init() calls while maintaining error recovery Impact: - Fixes all 8 storage adapters (FileSystem, Memory, S3, R2, GCS, Azure, OPFS, Historical) - Init now completes in ~1 second on fresh installation (was hanging) - Workshop team can now use v6.0.0 features without infinite loop - No new test failures (1178 tests passing) Files: - src/storage/baseStorage.ts: Move isInitialized = true to top of init() - CHANGELOG.md: Document v6.0.1 hotfix Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
parent
42ae5be455
commit
4d300e8ed3
2 changed files with 45 additions and 11 deletions
|
|
@ -259,22 +259,31 @@ export abstract class BaseStorage extends BaseStorageAdapter {
|
|||
* IMPORTANT: If your adapter overrides init(), call await super.init() first!
|
||||
*/
|
||||
public async init(): Promise<void> {
|
||||
// Load type statistics from storage (if they exist)
|
||||
await this.loadTypeStatistics()
|
||||
// v6.0.1: CRITICAL FIX - Set flag FIRST to prevent infinite recursion
|
||||
// If any code path during initialization calls ensureInitialized(), it would
|
||||
// trigger init() again. Setting the flag immediately breaks the recursion cycle.
|
||||
this.isInitialized = true
|
||||
|
||||
// v6.0.0: Create GraphAdjacencyIndex (lazy-loaded, no rebuild)
|
||||
// LSM-trees are initialized on first use via ensureInitialized()
|
||||
// Index is populated incrementally as verbs are added via addVerb()
|
||||
try {
|
||||
prodLog.debug('[BaseStorage] Creating GraphAdjacencyIndex...')
|
||||
this.graphIndex = new GraphAdjacencyIndex(this)
|
||||
prodLog.debug(`[BaseStorage] GraphAdjacencyIndex instantiated (lazy-loaded), graphIndex=${!!this.graphIndex}`)
|
||||
// Load type statistics from storage (if they exist)
|
||||
await this.loadTypeStatistics()
|
||||
|
||||
// v6.0.0: Create GraphAdjacencyIndex (lazy-loaded, no rebuild)
|
||||
// LSM-trees are initialized on first use via ensureInitialized()
|
||||
// Index is populated incrementally as verbs are added via addVerb()
|
||||
try {
|
||||
prodLog.debug('[BaseStorage] Creating GraphAdjacencyIndex...')
|
||||
this.graphIndex = new GraphAdjacencyIndex(this)
|
||||
prodLog.debug(`[BaseStorage] GraphAdjacencyIndex instantiated (lazy-loaded), graphIndex=${!!this.graphIndex}`)
|
||||
} catch (error) {
|
||||
prodLog.error('[BaseStorage] Failed to create GraphAdjacencyIndex:', error)
|
||||
throw error
|
||||
}
|
||||
} catch (error) {
|
||||
prodLog.error('[BaseStorage] Failed to create GraphAdjacencyIndex:', error)
|
||||
// Reset flag on failure to allow retry
|
||||
this.isInitialized = false
|
||||
throw error
|
||||
}
|
||||
|
||||
this.isInitialized = true
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue