Skip to content

feat: (critical) implement startup stability fixes for docker (increase timeout)#11154

Open
khoinp1012 wants to merge 1 commit intoappwrite:mainfrom
khoinp1012:fix/docker-stability
Open

feat: (critical) implement startup stability fixes for docker (increase timeout)#11154
khoinp1012 wants to merge 1 commit intoappwrite:mainfrom
khoinp1012:fix/docker-stability

Conversation

@khoinp1012
Copy link

These are simple but very critical fixes:

1. Increased Database Connection Timeout (Primary Fix)

File: app/init/registers.php

  • Increased PDO::ATTR_TIMEOUT from 3 seconds to 10 seconds
  • Gives MariaDB sufficient time to initialize before the application connects
  • Addresses the root cause of the race condition

2. Resilient Collection Initialization (Safety Net)

File: app/http.php

  • Wrapped collection creation loop in try-catch block
  • Prevents fatal crashes if individual collections fail to initialize
  • Logs warnings instead of crashing, allowing the server to continue startup
  • Implements defensive programming for long-term stability

🧪 Verification

Negative Test (Before Fix)

  • Tested with vanilla main branch code
  • Fresh Docker volumes (clean database)
  • Result: Fatal error after 10 connection attempts, server crashed

Positive Test (After Fix)

  • Tested with stability fixes applied
  • Fresh Docker volumes (clean database)
  • Result: Server started successfully
  • Log output: Server started successfully (max payload is 12,582,912 bytes)
  • All collections created without errors

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Jan 18, 2026

📝 Walkthrough

Walkthrough

Two files were modified to improve database setup resilience and connection reliability. The HTTP initialization now wraps per-collection creation logic in a try-catch block to gracefully handle exceptions during collection preparation, logging warnings instead of failing the entire setup process. Simultaneously, the MySQL/MariaDB connection timeout was increased from 3 seconds to 10 seconds in the initialization registers.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~12 minutes

🚥 Pre-merge checks | ✅ 2 | ❌ 1
❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately describes the main changes: implementing startup stability fixes for Docker with timeout increase, which directly reflects the primary fix (PDO timeout) and secondary safety net (try-catch wrapper).
Description check ✅ Passed The description is comprehensive and directly related to the changeset, detailing both the timeout increase and try-catch implementation with verification results.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@github-actions
Copy link

Security Scan Results for PR

Docker Image Scan Results

Package Version Vulnerability Severity
libpng 1.6.51-r0 CVE-2025-66293 HIGH
libpng-dev 1.6.51-r0 CVE-2025-66293 HIGH

Source Code Scan Results

🎉 No vulnerabilities found!

Copy link
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 1

🤖 Fix all issues with AI agents
In `@app/init/registers.php`:
- Line 267: The CLI/worker db resource still uses SQL::getPDOAttributes() which
returns a 3s timeout; update the db registration to use the same 10s timeout as
the pool by either changing SQL::getPDOAttributes() to return PDO::ATTR_TIMEOUT
=> 10 or overriding the attributes in the db resource registration (the closure
that creates the PDO used by the "db" service) to set \PDO::ATTR_TIMEOUT => 10
so worker/CLI connections match the pool.
🧹 Nitpick comments (1)
app/http.php (1)

212-242: Good resilience improvement for startup stability.

The try-catch block correctly prevents individual collection creation failures from crashing the entire server startup. The warning log maintains visibility into issues.

Two minor observations:

  1. Consider catching more specific exceptions: The Migration.php reference catches DuplicateException specifically. You could consider catching DuplicateException separately for cleaner logging (similar to line 393), while still catching \Exception as a fallback:
♻️ Optional: More specific exception handling
         try {
             if (!$database->getCollection($key)->isEmpty()) {
                 continue;
             }
             // ... attribute/index mapping ...
             $database->createCollection($key, $attributes, $indexes);
+        } catch (DuplicateException $e) {
+            Console::info("    └── Skip: collection '{$key}' already exists");
         } catch (\Exception $e) {
             Console::warning("    └── Failed to create collection '{$key}': " . $e->getMessage());
         }
  1. Potential inconsistency: The sharedTablesV2 collection creation loop (lines 402-416) doesn't have similar try-catch protection. Consider whether it should also be wrapped for consistency.

return new PDOProxy(function () use ($dsnHost, $dsnPort, $dsnUser, $dsnPass, $dsnDatabase) {
return new PDO("mysql:host={$dsnHost};port={$dsnPort};dbname={$dsnDatabase};charset=utf8mb4", $dsnUser, $dsnPass, [
\PDO::ATTR_TIMEOUT => 3, // Seconds
\PDO::ATTR_TIMEOUT => 10, // Seconds
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

🧩 Analysis chain

🏁 Script executed:

# First, locate the file and check its size
find . -name "registers.php" -type f | head -20

Repository: appwrite/appwrite

Length of output: 85


🏁 Script executed:

# Check what SQL::getPDOAttributes() returns
rg "getPDOAttributes" -A 30 --type php

Repository: appwrite/appwrite

Length of output: 1711


🏁 Script executed:

# Read the specific lines mentioned in the review
if [ -f "app/init/registers.php" ]; then
  echo "=== Lines 260-275 (around line 267) ===";
  sed -n '260,275p' app/init/registers.php | cat -n;
  echo "";
  echo "=== Lines 325-350 (around lines 330-344) ===";
  sed -n '325,350p' app/init/registers.php | cat -n;
fi

Repository: appwrite/appwrite

Length of output: 2086


🏁 Script executed:

# Find the SQL class definition
find . -name "*.php" -type f | xargs rg "class SQL" | head -5

Repository: appwrite/appwrite

Length of output: 554


🏁 Script executed:

# Search for getPDOAttributes function definition
rg "function getPDOAttributes\(\)" -A 20 --type php

Repository: appwrite/appwrite

Length of output: 43


🏁 Script executed:

# Search in the vendor directory for getPDOAttributes
rg "getPDOAttributes" vendor/utopia-php/database/src/Database/Adapter/SQL.php -A 20

Repository: appwrite/appwrite

Length of output: 901


🏁 Script executed:

# Also check the file directly
cat vendor/utopia-php/database/src/Database/Adapter/SQL.php | grep -A 20 "getPDOAttributes"

Repository: appwrite/appwrite

Length of output: 901


Timeout increase incomplete: Workers/CLI connections still use 3-second timeout.

The connection pool now uses a 10-second timeout, but the db resource at lines 330-344 (which handles CLI/worker connections) relies on SQL::getPDOAttributes() from the vendor library, which still returns a 3-second timeout. This creates an inconsistency where workers/CLI may timeout before the main connection pool.

Either update SQL::getPDOAttributes() to return 10 seconds, or explicitly set the timeout in the db resource registration to match the connection pool timeout.

🤖 Prompt for AI Agents
In `@app/init/registers.php` at line 267, The CLI/worker db resource still uses
SQL::getPDOAttributes() which returns a 3s timeout; update the db registration
to use the same 10s timeout as the pool by either changing
SQL::getPDOAttributes() to return PDO::ATTR_TIMEOUT => 10 or overriding the
attributes in the db resource registration (the closure that creates the PDO
used by the "db" service) to set \PDO::ATTR_TIMEOUT => 10 so worker/CLI
connections match the pool.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant