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

[Bug]: event-bus-redis processor execute event before subscriber are loaded #10822

Open
pmc12thsuki opened this issue Jan 5, 2025 · 0 comments · May be fixed by #10823
Open

[Bug]: event-bus-redis processor execute event before subscriber are loaded #10822

pmc12thsuki opened this issue Jan 5, 2025 · 0 comments · May be fixed by #10823

Comments

@pmc12thsuki
Copy link

Package.json file

{
  "name": "api",
  "version": "0.0.1",
  "description": "A starter for Medusa projects.",
  "author": "Medusa (https://medusajs.com)",
  "license": "MIT",
  "keywords": [
    "sqlite",
    "postgres",
    "typescript",
    "ecommerce",
    "headless",
    "medusa"
  ],
  "scripts": {
    "build": "medusa build",
    "seed": "medusa exec ./src/scripts/seed.ts",
    "start": "medusa start",
    "lint": "eslint \"src/**/*.ts\" --fix",
    "migration": "medusa db:migrate",
    "medusa": "medusa",
    "exec": "medusa exec",
    "dev": "medusa develop"
  },
  "dependencies": {
    "@aws-sdk/client-ses": "3.650.0",
    "@aws-sdk/credential-providers": "3.614.0",
    "@medusajs/framework": "^2.1.0",
    "@medusajs/medusa": "^2.1.0",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/knex": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "@simoko/tw-zip": "^0.1.4",
    "awilix": "^8.0.1",
    "axios": "^1.7.3",
    "bluebird": "^3.7.2",
    "date-fns": "^3.6.0",
    "dayjs": "^1.11.13",
    "express": "^4.17.2",
    "lodash": "^4.17.21",
    "multer": "1.4.5-lts.1",
    "nanoid-cjs": "^0.0.7",
    "newrelic": "^12.6.0",
    "pg": "^8.13.0",
    "xlsx": "^0.18.5"
  },
  "devDependencies": {
    "@medusajs/cli": "2.1.0",
    "@medusajs/test-utils": "^2.1.0",
    "@mikro-orm/cli": "5.9.7",
    "@mikro-orm/core": "5.9.7",
    "@mikro-orm/migrations": "5.9.7",
    "@mikro-orm/postgresql": "5.9.7",
    "@stdlib/number-float64-base-normalize": "0.0.8",
    "@swc/core": "1.5.7",
    "@swc/jest": "^0.2.36",
    "@types/express": "^4.17.13",
    "@types/lodash": "^4.17.7",
    "@types/mime": "1.3.5",
    "@types/multer": "^1.4.12",
    "@types/newrelic": "^9.14.5",
    "@types/node": "^20.0.0",
    "@types/react": "^18.3.2",
    "@typescript-eslint/eslint-plugin": "^6.0.0",
    "@typescript-eslint/parser": "^6.0.0",
    "eslint": "^8.42.0",
    "eslint-config-prettier": "^9.0.0",
    "eslint-plugin-prettier": "^5.0.0",
    "eslint-plugin-simple-import-sort": "^12.1.0",
    "jest": "^29.7.0",
    "prop-types": "^15.8.1",
    "scrypt-kdf": "^2.0.1",
    "ts-node": "^10.9.2",
    "typescript": "^5.6.2"
  },
  "engines": {
    "node": ">=20"
  }
}

Node.js version

20.14.0

Database and its version

16.3

Operating system name and version

macOS 14.3.1

Browser name

No response

What happended?

What happened

When there are pending events in Redis waiting to be processed, the following issue occurs during application startup:

  1. The event-bus-redis module is loaded, and the bullWorker begins processing the events automatically.
  2. Custom subscribers are loaded after.
  3. As a result, the subscribers log messages such as Processing XXX which has 0 subscribers and mark these events as completed without proper handling.

A common scenario is: In horizontally scaled environments, when new application instances are started (e.g., due to scaling or redeployment), they immediately begin consuming events from Redis before custom subscribers are loaded.

Steps to Reproduce

  1. Run script to emit event and leave event in Redis (can be done by setting WORKER_MODE=server)
  2. Start the application.
  3. Observe the logs and behavior of the events being processed before subscribers are loaded.

Expected behavior

Events should not be processed until all subscribers are fully loaded.

Actual behavior

Events may be processed before the relevant subscribers have been initialized, which could cause critical functionality to be missed.

Link to reproduction repo

medusa(v2)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants