Skip to content

Commit

Permalink
TASK: Guards against recursion in get content repository and memory o…
Browse files Browse the repository at this point in the history
…verflow
  • Loading branch information
mhsdesign committed Nov 2, 2024
1 parent 397737c commit 5f8b999
Showing 1 changed file with 10 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,9 @@ public function __construct(
$this->projectionsAndCatchUpHooks = $projectionsAndCatchUpHooksFactory->build($this->projectionFactoryDependencies);
}

// guards against recursion and memory overflow
private bool $isBuilding = false;

// The following properties store "singleton" references of objects for this content repository
private ?ContentRepository $contentRepository = null;
private ?EventPersister $eventPersister = null;
Expand All @@ -89,6 +92,10 @@ public function getOrBuild(): ContentRepository
if ($this->contentRepository) {
return $this->contentRepository;
}
if ($this->isBuilding) {
throw new \RuntimeException(sprintf('Content repository "%s" was attempted to be build in recursion.', $this->contentRepositoryId->value), 1730552199);
}
$this->isBuilding = true;

$contentGraphReadModel = $this->projectionsAndCatchUpHooks->contentGraphProjection->getState();
$commandHandlingDependencies = new CommandHandlingDependencies($contentGraphReadModel);
Expand Down Expand Up @@ -127,7 +134,7 @@ public function getOrBuild(): ContentRepository
)
);

return $this->contentRepository = new ContentRepository(
$this->contentRepository = new ContentRepository(
$this->contentRepositoryId,
$publicCommandBus,
$this->projectionFactoryDependencies->eventStore,
Expand All @@ -141,6 +148,8 @@ public function getOrBuild(): ContentRepository
$this->clock,
$contentGraphReadModel
);
$this->isBuilding = false;
return $this->contentRepository;
}

/**
Expand Down

0 comments on commit 5f8b999

Please sign in to comment.