Repository navigation
fix(migrate-auth-secret): exit cleanly when there are no 2FA records - #4394
Merged
Siumauricio merged 1 commit intoMay 12, 2026
Merged
Siumauricio merged 1 commit into
Siumauricio merged 1 commit into
Conversation
The empty-records branch of `main()` returned without calling `process.exit(0)`, leaving the Drizzle Postgres connection pool holding the event loop open. The `migrate-auth-secret` process then hangs indefinitely after printing "No 2FA records found, nothing to migrate." causing the upstream `0.29.3.sh` security migration script (which calls this via `docker exec`) to never reach its final `docker service update` step that mounts the new Docker Secret. Operators end up with the new secret created but the dokploy service still configured with the hardcoded `BETTER_AUTH_SECRET`, while believing the migration completed. Match the success branch a few lines below which already does `process.exit(0)`, and the pattern used in sibling scripts `reset-password.ts` and `reset-2fa.ts`. Closes Dokploy#4392
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds
process.exit(0)to the empty-2FA-records branch ofapps/dokploy/scripts/migrate-auth-secret.tsso the script terminates cleanly when there is nothing to migrate.Currently the branch just
returns frommain(). Because thedbimport opens a Drizzle/pg connection pool with un-unref'd handles, Node's event loop never empties and the process hangs forever, even though every migration responsibility has completed.This is the root cause documented in #4392 — the
0.29.3.shsecurity migration script runs this file viadocker exec, then expects to continue and run the criticaldocker service update --secret-add ... --env-add BETTER_AUTH_SECRET_FILE=... --env-rm BETTER_AUTH_SECRET dokploystep. When this script hangs, the outer shell script hangs too (because ofset -e+ synchronousdocker exec), and the dokploy service is never reconfigured to use the new secret. Thedokploy-auth-secretDocker Secret is created but never mounted, so the instance silently stays vulnerable while the operator believes the patch was applied.Closes #4392.
The change
One line:
if (records.length === 0) { console.log("✅ No 2FA records found, nothing to migrate."); - return; + process.exit(0); }This matches:
process.exit(0).apps/dokploy/scripts/reset-password.tsandapps/dokploy/scripts/reset-2fa.ts, which both callprocess.exit(0)after their main work.Test plan
I reproduced the hang on a real install before opening #4392:
SELECT COUNT(*) FROM two_factor = 0curl -sSL https://dokploy.com/security/0.29.3.sh | bash✅ No 2FA records found, nothing to migrate.then hung;/proc/<pid>/wchanwasep_pol, ~140MB RSS, 11 threads — Node's event loop idle, never exitingdocker service updatemyself; full diagnostics in Post-upgrade security script (0.29.3.sh) hangs in migrate-auth-secret when there are 0 two_factor records, leaving service unreconfigured #4392With this patch,
process.exit(0)causes Node to terminate the runtime immediately, releasing any open pg/Docker socket handles. The bash script'sdocker execthen returns 0, and execution continues to thedocker service update --secret-add ...step the way it was meant to.I have not stood up a full local Dokploy dev environment to re-run the entire
0.29.3.shpipeline end-to-end against this branch — the fix is a singleprocess.exit(0)call whose behavior is fully determined by the Node runtime, and the failing branch already prints its completion message before returning, so the new exit code is reached at exactly the same point that previously hung. Happy to do further testing if a maintainer wants something specific.Out of scope, but flagged in #4392
There is a related issue with the outer shell script (
0.29.3.sh) that this PR does not address: its early-exit idempotency check only verifies that thedokploy-auth-secretDocker Secret exists, not that the dokploy service spec actually mounts it and usesBETTER_AUTH_SECRET_FILE. A user whose first run hung after the secret was created will see✅ Auth secret is already configured!on a re-run and bail out, despite the service still being unpatched. Worth tightening that check in the shell script (suggested patch in the issue), but it lives outside this repo so I haven't touched it here.