nextcloud / nextcloud/server

Cron might still be running during an update

Open
#28,508 5 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

1. to develop feature: install and update high technical debt
Dominant language
PHP
Stars
36.9k
Forks
5.2k
Avg merge
2d 3h
Merged PRs (30d)
713

Description

Steps (inferred)
  1. Have a NC cron job run that takes 5+ minutes to run
  2. Swap the PHP code to a newer version of NC
  3. 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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.