Repository navigation
Description
Problem
On installs with many pending migrations, the login page's migration ajax request (Login::migrate()) can exceed webserver, reverse-proxy, or PHP socket timeouts, surfacing "Connection error. Please try again." to the user even though the migrations complete successfully.
Confirmed via log inspection (Laragon/Apache + MySQL 8.4 locally): every migration step logs success, the full run completes in ~90s, but the browser still receives a connection error because no response bytes are sent to the client until the entire batch finishes. Any intermediate proxy/webserver layer with an idle-connection timeout (Apache Timeout, nginx proxy_read_timeout, corporate/AV proxies, etc.) can kill the socket mid-run.
Bumping set_time_limit, jQuery ajax timeout, default_socket_timeout, and Apache's Timeout directive does not reliably fix this, since:
- Not all hosting environments give admins access to php.ini / httpd.conf (shared hosting, managed panels).
- The failure point can be any hop in the chain (proxy, load balancer, AV/firewall), not just Apache or PHP.
Proposed solution
Convert the single long-running migration request into a sequence of small requests — one HTTP round-trip per pending migration — driven by a client-side loop. This removes the dependency on any server/proxy timeout configuration and works unmodified on any host.
Design
app/Libraries/MY_Migration.php— add a new public method, e.g.runNextMigration(?string $group = null): ?object, that mirrorsCodeIgniter\Database\MigrationRunner::latest()'s setup (ensureTable, lock acquire/release, group filtering) but executes only the next pending migration (via the existingprotectedmigrate('up', $migration)+addHistory()), then returns the migration object that was run, ornullif none remain. Throws the sameRuntimeExceptionon failure aslatest()for parity. No CodeIgniter vendor/core changes required —MY_Migrationalready extendsMigrationRunnerand all needed members areprotected/publicand visible to the subclass.app/Controllers/Login.php—migrate()callsrunNextMigration()once per request instead of->latest(). Response JSON becomes{success: bool, done: bool, version: int|null, message?: string}, wheredone = trueoncerunNextMigration()returnsnull.app/Views/login.php— replace the single$.ajaxcall with arunStep()function that calls itself recursively whiledone === false, updating the progress UI between steps (e.g. showing the version just migrated), and finishing with the existing success/error UI oncedone === trueor an ajax error occurs. This is seamless to the user: no page reload, no re-entering credentials — the page and JS state stay alive across the whole loop, same as a single request today, just broken into many small ones under the hood.
Explicitly out of scope for this change
Login::index()'s non-ajax fallback migration path (used only when JS/ajax is unavailable) — stays a single long-running request.MY_Migration::migrateToCI4()(one-time legacy CI3→CI4 migration-table conversion) — stays a single-shot call before the stepped loop begins; it's fast bookkeeping, not the slow part.- Server/proxy timeout configuration docs — not needed once this is implemented, since no single request runs longer than one migration step.
Notes
$lockdefaults tofalsein this app's migration config (single-admin install flow); each step request would still acquire/release the lock independently if enabled, same semantics as today.- The existing
login_checkcredential validation inmigrate()would re-run on every step request (same values resubmitted each time) — negligible overhead, no behavior change.
Activity
jekkos commentedon Oct 22, 2026
This will be resolved by offloading the migration run to a background task (job queue) — same direction as noted in #4769. The client receives an immediate "migration queued" response, and the worker runs to completion regardless of connection state or proxy timeouts. No more false 'Connection error' for long migration sequences. Targeting 3.4.4 alongside the job queue infrastructure (#4703 / #4725).
objecttothis commentedon Oct 22, 2026
If each migration is run in a separate job then it would be quite rare to run into timeouts. I think probably the way to implement this is that a migration job runs one migration, then checks to see if there are more migrations and just before completing the job, schedules the next migration to kick off.
objecttothis commentedon Oct 23, 2026
Claude Issue Checker Agent (cc @objecttothis)
Investigated against current
master.Status: Still present (proposed fix not implemented).
app/Controllers/Login.phpstill has the single-shot migration flow described in this issue:index()andmigrate()both call$migration->setNamespace('App')->latest()once, wrapped only inset_time_limit(3600)— there is norunNextMigration()method anywhere in the codebase (confirmed via repo-wide code search, zero matches).app/Libraries/MY_Migration.phphas no stepped-migration method either — it still only exposes the inheritedlatest()-style behavior used as one long-running call.Login::migrate()) returns a single{success, message}JSON after the entire batch completes, not the proposed{success, done, version}per-step protocol.So a long migration run can still exceed webserver/proxy idle timeouts and surface the "Connection error" message even though migrations ultimately succeed, exactly as described. No related PR is currently linked to this issue.
objecttothis commentedon Nov 13, 2026
regarding @jekkos suggestion, we are already developing a job queue system in a way to have different queues. I suspect the way we should do this is to have a dedicated migration queue which gets priority for importance, and timeout length. We also need to remove throttling so that it runs. We may need to drop requirement for login to run migrations for this or at least have the migration queue bypass it. We do likely need to change the check in the login screen to prevent login until migrations complete. Each migration should finish by checking for another migration and creating the job for it if the next migration exists. The initial check for migrations and creating the first job should remain in the login screen or a CI tasks scheduled checker. It would be helpful to add a live migration status on the login screen so users can see progress. @coderabbitai please comment on feasibility and design.
coderabbitai commentedon Nov 13, 2026
Analysis chain
Script executed:
Length of output: 91898
Script executed:
Length of output: 47870
Script executed:
Length of output: 29232
@objecttothisThe design is feasible, but the queue needs a bootstrap path that works before the queue’s database tables and settings exist. That is the main constraint for fresh installs and older upgrades.The current code still runs the full migration sequence in one request. One correction to the earlier investigation:
Login::index()andLogin::migrate()now callMY_Migration::runLocked(), which wrapslatest()in a database lock.Login::index()also callsmigrateToCI4()before that lock.I suggest this design:
#4725defaults to database storage, and its worker reads application settings and throttle tables.#4725, queue order and per-queue priority are separate, and the worker checks its deadline between jobs. A single migration can still exceed PHP, host, or reservation limits. Web-mode execution also needs a verified detached execution path;fastcgi_finish_request()is not available on every host.Load_configalready destroys sessions when the database is not current, but the gate should also cover running and failed states. Let the login page poll a read-only status endpoint for queued, running, completed, failed, and stalled states. Limit unauthenticated details and show actionable recovery guidance.I would test fresh installs, CI3 upgrades, simultaneous triggers, worker interruption at each handoff, a single long migration, and all supported worker modes. Also verify the login flow when no detached worker is available, so the upgrade does not remain queued indefinitely.
You are interacting with an AI system.
objecttothis commentedon Nov 13, 2026
Even with current master changes, timeouts are hit on large pre-existing databases and the CI3 to CI4 migration does not properly complete which causes a decryption exception to be thrown as soon as you attempt to access CI3 encrypted data with a CI4 key.
Ultimately we need a solution to this problem. Ideally an interim solution since jobs is a ways off from being completed.
jekkos commentedon Nov 13, 2026
@CodeRabbit is there an easy way to run migration in async fashion where we just offload it to a thread for now?
coderabbitai commentedon Nov 13, 2026
Analysis chain
Script executed:
Length of output: 24208
web_search executed:
According to official PHP documentation, what does fastcgi_finish_request() do under PHP-FPM, does it release the PHP-FPM worker while PHP continues, and how do script execution and timeout limits or client disconnects affect continued processing? Check PHP manual documentation.Length of output: 13042
Script executed:
Length of output: 44769
@jekkosYes. For PHP-FPM, the smallest interim option is probablyfastcgi_finish_request(), rather than a thread. It sends the HTTP response and lets the same PHP process continue the migration. It does not require the job queue. PHP documentationIt is not a durable background job. The migration still occupies a PHP-FPM worker, and PHP or host timeouts can still terminate it. A restart can also interrupt it.
I suggest this interim flow:
app/Views/login.phptreats a successful response as completion. Report completion only after the migration succeeds. Show failed or interrupted states and keep application access blocked until success.migrateToCI4()call inapp/Controllers/Login.php, Line 35, inside the same lock. It currently runs beforerunLocked().fastcgi_finish_request()is unavailable, report that async execution is unavailable rather than claiming the migration started. Check FPM capacity too: with one worker, status polling may wait for the migration.Login::migrate()already usesignore_user_abort(true)and a one-hour limit. Those settings do not prevent host timeouts or process termination.Encryption recovery remains critical. The conversion writes the new key before saving the converted secrets. A hard process termination can interrupt that sequence. Keep a matching database and
.envbackup before upgrading, and do not blindly retry an interrupted conversion. This also follows the existing project guidance to preserve the legacy key until conversion succeeds and keep automatic web initialization for fresh installs.Learnings used
You are interacting with an AI system.