Skip to content

fix: fail migrations whose source or destination stops answering - #14330

Merged
ChiragAgg5k merged 5 commits into
mainfrom
fix/migration-hang
Oct 11, 2026
Merged

ChiragAgg5k merged 5 commits into
mainfrom
fix/migration-hang

Conversation

@ChiragAgg5k

@ChiragAgg5k ChiragAgg5k commented Oct 10, 2026 •

Copy link
Copy Markdown
Member

Migration E2E tests intermittently time out in CI with the migration stuck in processing. The worker picks the job up and sets processing, then logs nothing (no error, no completion), while later migrations finish on other workers.

Cause

None of the migration worker's HTTP calls had a timeout. When a source or destination accepts the connection and never answers, the worker coroutine blocks in curl_exec forever. The catch/finally that marks the migration failed never runs.

Captured by dumping the stuck handler's stack while the regression test below runs without the fix:

#0 curl_exec                       vendor/appwrite/appwrite/src/Appwrite/Client.php:504
#1 Appwrite\Client->call           .../Services/Users.php:56
#2 Appwrite\Services\Users->list   vendor/utopia-php/migration/.../Sources/Appwrite.php:409
#3 Sources\Appwrite->reportAuth    .../Sources/Appwrite.php:355
#4 Sources\Appwrite->report        src/Appwrite/Platform/Workers/Migrations.php:338
#5 Migrations->processSource       src/Appwrite/Platform/Workers/Migrations.php:609

Fix

  • fix: time out stalled source and destination requests utopia-php/migration#232: 10s connect timeout everywhere. Target::call abandons a response that sends no bytes for 30s, and the Appwrite SDK clients cap each request at 30s. A stall now throws, and the worker records failed with the error (Operation timed out after 30000 milliseconds with 0 bytes received).
  • The worker's own scope-probe Client in authenticateSource() gets the same limits.

Requires utopia-php/migration ^2.0.9, the release with the change from utopia-php/migration#232.

Tests

testAppwriteMigrationFailsWhenSourceNeverAnswers opens a listening socket in the test process that never accepts. Connections complete from the backlog and nothing ever replies. It then runs an Appwrite migration against it and expects failed with errors.

result
without the fix Failed asserting ... 'finished' / +'processing' after 64s; worker blocked in curl_exec
with the fix OK in 34s; migration failed, stage: finished, error recorded

The Migrations suite was also run repeatedly the way CI runs it (paratest --processes 1 --functional), plus 6-process concurrent runs. The results are in the comment below.

Closes #14331

The migration worker's HTTP calls had no timeouts. A source or destination
that accepted the connection and never replied held the worker in curl_exec
forever, so the migration stayed processing with nothing logged and the
next jobs went to other workers.

utopia-php/migration now times out stalled requests, so report and transfer
calls throw and the worker records the migration as failed with the error.
The worker's own scope probe client gets the same limits.
@luxor-code-review

luxor-code-review Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

Review complete. 🟡 2 medium

💬 Inline comments (1)

📍 Findings outside the diff (1) — 🟡 1 medium — defects on lines GitHub can't attach comments to

🟡 Medium — Probe timeouts misreported as source unauthorized · Migrations.php:362–364 · unchanged line

// src/Appwrite/Platform/Workers/Migrations.php
362	        } catch (AppwriteException $error) {
363	            throw new Exception(Exception::MIGRATION_SOURCE_UNAUTHORIZED, previous: $error);
364	        }

authenticateSource rethrows every AppwriteException from the probe as Exception::MIGRATION_SOURCE_UNAUTHORIZED without distinguishing transport failures from HTTP status failures (src/Appwrite/Platform/Workers/Migrations.php:362-364). The connect and total timeouts added in this PR make a hung source surface as an AppwriteException inside this same catch. A user whose source host accepts connections but never replies now sees an unauthorized-key error, sending them to debug API keys instead of network reachability.

🧹 Nitpicks (1) — 🟢 1 low
  • 🟢 Pin utopia-php/migration to a dev branch instead of a tag (composer.json:158) — The utopia-php/migration constraint was changed from a stable range to the dev branch alias dev-fix/request-timeouts as 2.0.9 (composer.json:158), and composer.lock resolves it to a branch commit rather than a tagged release.

The change adds timeout configuration (Target::CONNECT_TIMEOUT / Target::REQUEST_TIMEOUT) to the migration source authentication client and validates failure behavior against a locally spawned dead listener in E2E. It also switches utopia-php/migration to a dev-branch alias pending a tagged release.

Files Change
composer.json Pins utopia-php/migration to dev-fix/request-timeouts as 2.0.9
src/Appwrite/Platform/Workers/Migrations.php Sets connect and total timeouts on the probe's source TablesDB client
tests/e2e/Services/Migrations/MigrationsBase.php Adds a test spawning a silent TCP listener and asserting the migration fails against it

Reviewed commit: d7164f0

@ghost

ghost commented Oct 10, 2026 •

Copy link
Copy Markdown

🟢 Tier S · Ready to merge

The PR bounds migration HTTP connection and response waits, updates the migration dependency to the release that provides request timeouts, and adds an E2E test for a source that accepts a connection but never responds. It also applies the same timeout limits to the worker's scope probe and logs chained exception causes when a migration fails.

Latest changes: The newest commit logs each previous exception's message, location, and trace when a migration fails.

Verdict New comments Fixed Still open
✅ Approved 0 0 0
📂 Walkthrough · 4
File Change
composer.json Requires utopia-php/migration ^2.0.9, which includes bounded request timeouts.
composer.lock Locks utopia-php/migration to the 2.0.9 release.
src/Appwrite/Platform/Workers/Migrations.php Sets timeouts on the scope-probe client and logs exception causes for failed migrations.
tests/e2e/Services/Migrations/MigrationsBase.php Adds an E2E regression test for an Appwrite source that never replies.
🔇 Filtered out · 1

Findings Hansi considered but did not post.

Finding Why
Avoid logging unfiltered chained exception messages Verifier: The finding does not establish a reachable secret-bearing exception message. This catch already logs the top-level raw message and trace, and the new loop extends those operator diagnostics to wrapped causes. Console::error writes to worker STDERR (packages/console/src/Console.php:42–44), not the migration API response. The separate user-facing boundary is handled at Migrations.php:700–731, where unknown errors receive a generic message before persistence; the original exception is deliberately retained for diagnostics. No repository rule prohibits chained-exception logging, and the possibility that an unspecified client response might contain a token is insufficient to demonstrate a security bug.

Reviewed the commits since e32983f · Details · Comment @hansi-codes review to re-run, or mention @hansi-codes with a question.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🟢 Tier S · Looks good to merge. Summary

@luxor-code-review luxor-code-review Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This PR wires connect and total request timeouts into the Appwrite migration source probe client and adds an E2E test with an unresponsive TCP listener, plus a dev-branch pin for utopia-php/migration.

Key findings

@github-actions

Copy link
Copy Markdown

Security rules

No new WARNING or ERROR findings from security rules.

32 existing findings tracked in .semgrep/baseline.json
  • php.appwrite.guest-write-without-abuse-limit (17)
  • php.appwrite.permissive-write-permission (8)
  • php.appwrite.secret-compare-timing (5)
  • php.appwrite.weak-secret-env-default (2)

Posted by Checks / Rules. Re-runs update this comment in place. Rule details and baseline: .semgrep/README.md.

@github-actions

github-actions Bot commented Oct 10, 2026 •

Copy link
Copy Markdown

✨ Benchmark results

Comparing main (before) → fix/migration-hang (after).

Metric Before After Change
🚀 Requests/sec 182.77 193.7 🟢 +6%
⏱️ Latency P50 94.82 ms 90.39 ms ⚪ -4.7%
⏱️ Latency P95 220.03 ms 206 ms 🟢 -6.4%
Per-scenario breakdown & investigation details

Metrics below reflect the current branch (after). Δ P95 compares against the base.

Scenario P50 (ms) P95 (ms) Requests RPS Δ P95 (ms)
API total 90.39 206 12,483 193.7 -14.02
Account 171.16 335.74 657 10.87 +8.47
TablesDB 87.19 158.87 6,789 108.62 -7.64
Storage 83.18 176.17 3,285 53.86 -28.45
Functions 127.87 252.39 1,752 29.39 -2.89

Top API waits (after)

API request Max wait (ms)
account.name.update 473.66
functions.variables.update 432.69
account.prefs.update 398.9
functions.create 372.78
storage.files.create 366.2

With timeouts on the scope probe, a request that never gets a response
surfaces as an AppwriteException with status 0, and authenticateSource
reported it as an unauthorized key. That sends the user to check their
key instead of reachability. Only a response status says anything about
the key.

@ghost ghost left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

🔵 Tier A · Looks good to merge. Summary

@ChiragAgg5k

Copy link
Copy Markdown
Member Author

@greptileai review

Workers are covered by E2E, not unit tests. The probe always calls the
local API, so its no-answer path cannot be staged from E2E; the timeouts
it relies on are covered in utopia-php/migration.
Sources wrap the error that stopped a migration, so the worker logged
only the wrapper and its trace ended at report(). Logging each previous
exception shows the request that actually failed, such as the SDK call
that timed out.
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.

Fail migrations whose source or destination stops answering

1 participant