Cron might still be running during an update
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 36.9k
- Forks
- 5.2k
- Avg merge
- 2d 3h
- Merged PRs (30d)
- 713
Description
Steps (inferred)
- Have a NC cron job run that takes 5+ minutes to run
- Swap the PHP code to a newer version of NC
- Run
occ upgrade
Expected result
Need to wait for cron to finish.
Actual result
Cron continues running and might cause side effects because it might be operating on data while the data is being migrated.
This is one case that could result in data loss, like https://github.com/nextcloud/spreed/issues/5518#issuecomment-845646929
Note: new cron jobs would not start because an upgrade enables maintenance mode, but existing ones that already started would continue running.
Version
The problem with https://github.com/nextcloud/spreed/issues/5518#issuecomment-845646929 was observed in NC 21 and 22
Possible solution
The upgrade code should wait (sleep) until all cron jobs have finished. To detect completion, the value of "oc_jobs.reserved" might help. And after a timeout of a minute or so, abort the upgrade with an error if a job is still running and did not finish.
Optional: when enabling maintenance mode, display a warning when cron jobs are still running (but don't wait?)
Killing cron jobs is likely not a good idea and is not reliably possible anyway from the PHP code.
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in the upgrade code and inspect how running cron jobs are represented by the oc_jobs.reserved value. Verify the interaction between maintenance mode and already-started jobs, then define the timeout and error behavior so an upgrade does not proceed while a job remains active.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend, database
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100