Skip to content

Conversation

@provokateurin
Copy link
Member

Sometimes when adding a new class via DI it does not work due to an infinite loop. Even worse, there is no logging, so it's not clear which class is causing the issue (since it can be a different class than the directly added one) and the webserver just dies due to the infinite loop.

This can be tested with the following diff:

diff --git a/lib/base.php b/lib/base.php
index b890cdb6dd7..c0484967f24 100644
--- a/lib/base.php
+++ b/lib/base.php
@@ -7,6 +7,7 @@ declare(strict_types=1);
  * SPDX-License-Identifier: AGPL-3.0-only
  */
 
+use OC\A;
 use OC\Profiler\BuiltInProfiler;
 use OC\Share20\GroupDeletedListener;
 use OC\Share20\Hooks;
@@ -189,6 +190,8 @@ class OC {
 			@touch($configFilePath);
 		}
 
+		Server::get(A::class)->someMethod();
+
 		// Check if config is writable
 		$configFileWritable = is_writable($configFilePath);
 		$configReadOnly = Server::get(IConfig::class)->getSystemValueBool('config_is_read_only');
diff --git a/lib/private/A.php b/lib/private/A.php
new file mode 100644
index 00000000000..b47fa53503b
--- /dev/null
+++ b/lib/private/A.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace OC;
+
+class A {
+	public function __construct(
+		private B $b,
+	) {
+	}
+
+	public function someMethod(): void {
+		$this->b->someMethod();
+	}
+}
diff --git a/lib/private/B.php b/lib/private/B.php
new file mode 100644
index 00000000000..e884e4fd43f
--- /dev/null
+++ b/lib/private/B.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace OC;
+
+class B {
+	public function __construct(
+		private C $c,
+	) {
+	}
+
+	public function someMethod(): void {
+		$this->c->someMethod();
+	}
+}
diff --git a/lib/private/C.php b/lib/private/C.php
new file mode 100644
index 00000000000..d19c21324ac
--- /dev/null
+++ b/lib/private/C.php
@@ -0,0 +1,14 @@
+<?php
+
+namespace OC;
+
+class C {
+	public function __construct(
+		private A $a,
+	) {
+	}
+
+	public function someMethod(): void {
+		$this->a->someMethod();
+	}
+}

@provokateurin provokateurin added this to the Nextcloud 33 milestone Nov 5, 2025
@provokateurin provokateurin requested a review from a team as a code owner November 5, 2025 10:59
@provokateurin provokateurin added enhancement 3. to review Waiting for reviews labels Nov 5, 2025
@provokateurin provokateurin requested review from Altahrim and ArtificialOwl and removed request for a team November 5, 2025 10:59
@provokateurin provokateurin marked this pull request as draft November 5, 2025 11:07
@provokateurin provokateurin added 2. developing Work in progress and removed 3. to review Waiting for reviews labels Nov 5, 2025
@provokateurin

This comment was marked as resolved.

Signed-off-by: provokateurin <kate@provokateurin.de>
@provokateurin provokateurin force-pushed the feat/di/abort-infinite-loop branch from 2d23398 to 3dbf848 Compare November 5, 2025 11:22
@provokateurin provokateurin marked this pull request as ready for review November 5, 2025 11:22
@provokateurin provokateurin added 3. to review Waiting for reviews and removed 2. developing Work in progress labels Nov 5, 2025
@provokateurin
Copy link
Member Author

Cypress is unrelated

@sorbaugh sorbaugh merged commit 2d0c5cf into master Nov 13, 2025
224 of 236 checks passed
@sorbaugh sorbaugh deleted the feat/di/abort-infinite-loop branch November 13, 2025 15:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

3. to review Waiting for reviews enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants