You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Do not explicitly exit the serverpod process after applying migrations #3959
When you run the server with the flags dart bin/main.dart --apply-migrations --role=maintenance the process will be killed with a call to exit.
This makes it impossible to run in this mode within a dart script that is supposed to execute other code after the migration is applied, as the process is killed as soon as the migration has completed.
Proposal
Do not make a call to exit but let the process die when it reaches the end of the main method.
Use Case
I have a stand alone migration script file where I want to apply the migration and then have custom logic after the migration is applied.
Alternatives
Wrap the apply migration code and instance of Serverpod in a dart process or split the code into multiple dart files and call them one after the other.
Additional context
This is the code that is causing this behavior inside server/serverpod.dart
A discussed approach for fixing this is to move all exit calls to the generated bin/main.dart instead of calling them directly on ExitException catches like this one:
This would be a breaking change, but we can instruct users on the migration guide to just add the try/catch block on their already existing main.dart file.
A more advance and complete approach that also addresses #3873 is to add database startup hooks (onOpen, beforeMigration, afterMigration, etc) to allow hooking custom code.
Activity
marcelomendoncasoares commentedon Sep 4, 2025
A discussed approach for fixing this is to move all
exitcalls to the generatedbin/main.dartinstead of calling them directly onExitExceptioncatches like this one:serverpod/packages/serverpod/lib/src/server/serverpod.dart
Lines 383 to 388 in a1a7fe6
This would be a breaking change, but we can instruct users on the migration guide to just add the try/catch block on their already existing
main.dartfile.A more advance and complete approach that also addresses #3873 is to add database startup hooks (
onOpen,beforeMigration,afterMigration, etc) to allow hooking custom code.