Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Side effect causing jobs to have same jobId #2633

Closed
batrudinych opened this issue Jul 29, 2023 · 1 comment · Fixed by #2634
Closed

Side effect causing jobs to have same jobId #2633

batrudinych opened this issue Jul 29, 2023 · 1 comment · Fixed by #2634
Labels

Comments

@batrudinych
Copy link
Contributor

batrudinych commented Jul 29, 2023

Description

In case the same repeat object is reused across several jobs, all the jobs result in having the same jobId in redis, hence only one of the created jobs gets executed (and has a proper entry in redis).
Subjectively, I, as a user of the library, consider this a bug.

See #2634 for resolution

Minimal, Working Test code to reproduce the issue.

'use strict'

const Bull = require('bull')
const redis = require('redis')
const { promisify } = require('util')

const testSchedule = { cron: '*/10 * * * *' }

async function main () {
  const client = redis.createClient()
  const hgetAsync = promisify(client.hget).bind(client)
  const keysAsync = promisify(client.keys).bind(client)
  const queue = new Bull('my-shiny-queue-1')

  await Promise.all([
    queue.add(
      'my-shiny-job-1',
      {},
      {
        jobId: 'my-shiny-job-1',
        repeat: testSchedule,
        removeOnComplete: true
      }
    ),
    queue.add(
      'my-shiny-job-2',
      {},
      {
        jobId: 'my-shiny-job-2',
        repeat: testSchedule,
        removeOnComplete: true
      }
    )
  ])

  const myShinyJobsList = await queue.getRepeatableJobs()
  console.log('job confs returned by bull', myShinyJobsList)

  const qKeys = await keysAsync('bull:my-shiny-queue-1:repeat:*')
  const realRedisData = await Promise.all(qKeys.map(k => hgetAsync(k, 'opts')))
  console.log('repeat conf from redis:')
  for (const rawStr of realRedisData) {
    const obj = JSON.parse(rawStr)
    console.log('key: %s, jobId: %s', obj.repeat.key, obj.repeat.jobId)
  }
}

main()
  .catch(console.error)
  .finally(() => process.exit())

Bull version

4.10.2

Additional information

script output:

job confs returned by bull [
  {
    key: 'my-shiny-job-2:my-shiny-job-2:::*/10 * * * *',
    name: 'my-shiny-job-2',
    id: 'my-shiny-job-2',
    endDate: null,
    tz: null,
    cron: '*/10 * * * *',
    every: null,
    next: 1690590600000
  },
  {
    key: 'my-shiny-job-1:my-shiny-job-1:::*/10 * * * *',
    name: 'my-shiny-job-1',
    id: 'my-shiny-job-1',
    endDate: null,
    tz: null,
    cron: '*/10 * * * *',
    every: null,
    next: 1690590600000
  }
]
repeat conf from redis:
key: my-shiny-job-1:my-shiny-job-1:::*/10 * * * *, jobId: my-shiny-job-2
key: my-shiny-job-2:my-shiny-job-2:::*/10 * * * *, jobId: my-shiny-job-2

Although queue returns correct data, the real data in redis is incorrect.

This happens due to the fact that the shared repeat object is mutated.

github-actions bot pushed a commit that referenced this issue Aug 8, 2023
## [4.11.1](v4.11.0...v4.11.1) (2023-08-08)

### Bug Fixes

* **queue:** deep clone opts ([#2634](#2634)) fixes [#2633](#2633) ([35f1da3](35f1da3))
@manast
Copy link
Member

manast commented Aug 8, 2023

🎉 This issue has been resolved in version 4.11.1 🎉

The release is available on:

Your semantic-release bot 📦🚀

@manast manast added the released label Aug 8, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants