Uploaded image for project: 'XWiki Platform'
  1. XWiki Platform
  2. XWIKI-25720

Scheduling a job from another wiki moves its execution to that wiki

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • Major
    • None
    • 18.4.6, 18.9.0
    • Scheduler
    • None
    • Unknown

    Description

      Problem

      When a scheduler job is scheduled, SchedulerPlugin#prepareJobStubContext() compares the job's contextDatabase with the wiki of the current request. When they differ, it replaces contextDatabase with the current wiki, saves the job page and builds the job's execution context for that wiki:

      String iDb = context.getWikiId();
      String cDb = job.getStringValue("contextDatabase");
      if ("".equals(cDb) || !iDb.equals(cDb)) {
          cDb = context.getWikiId();
          job.setStringValue("contextDatabase", cDb);
      

      So a job scheduled or rescheduled from a request in another wiki (for example a script calling $xwiki.scheduler.scheduleJob() on a job page of a subwiki from the main wiki) runs in that other wiki from then on, while its page stays in its own wiki. Nothing fails: the job runs at its usual time, but its queries and document lookups target the wrong wiki, so it silently does nothing.

      This happened on extensions.xwiki.org: the ExtensionCode.UpdateInstalledExtensionCountScheduler job of the extensions wiki got rescheduled from the main wiki, its contextDatabase became xwiki (version 830.1 of the job page, which changes only that property), and for more than a week the job found no extension pages and updated no install counts. Rescheduling it from the extensions wiki put contextDatabase back to extensions and fixed it.

      Steps to reproduce

      1. In a subwiki, create a scheduler job whose script logs xcontext.wikiId.
      2. From a page of the main wiki, call $xwiki.scheduler.scheduleJob($xwiki.getDocument('subwiki:Space.Job').getObject('XWiki.SchedulerJobClass')) (or unschedule it, then schedule it).
      3. Trigger the job.

      Expected: the job runs in the subwiki, where its page is.
      Actual: the job page now has contextDatabase=xwiki and the job runs in the main wiki.

      Proposal

      Take the execution wiki from the wiki of the job page (job.getDocumentReference().getWikiReference()) rather than from the request that schedules it. The current code already overwrites contextDatabase each time the wiki differs, so the property can't currently be used to run a job in another wiki.

      The code was read on 18.4.6 and on master (13b3aaed64d).

      PS: This post was co-written with Claude Code.

      Attachments

        Activity

          People

            Unassigned Unassigned
            vmassol Vincent Massol
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated: