Skip to content

Message Queue consumer issue : context is not reset between messages #37870

Open
@Nuranto

Description

@Nuranto

Preconditions and environment

  • Magento version 2.4.6-p2

Steps to reproduce

  1. Create a command test:publish_message that publish a message on a queue
  2. Create a consumer that loads and display a product stock qty (via stock registry), and logs it. (initial qty = 100)
  3. Launch the consumer
  4. Run the test:publish_message
  5. Edit the qty of the product on backend (qty : 200)
  6. Run the test:publish_message
  7. Check consumer's logs

Expected result

Logs should display :

100
200

Actual result

Logs display :

100
100

Additional information

This is because both messages are running in the same environement, without any reset of any kind.

With a high value of --max-messages or with consumers-wait-for-messages a consumer can run for days before restarting. This can have very bad consequences for some consumers.

I guess the easiest and safest solution is to run the message execution in a new process. But maybe it could also do the trick to - somehow - reset ObjectManager between each messages (But I'm afraid about memory consumption with that).

Workaround :

(with --consumers-wait-for-messages=1)

while true; do bin/magento queue:consumers:start --max-messages=1 -vvv consumer.name; done

This is a lot slower :/ but it solves the issue while waiting for a fix.

Release note

No response

Triage and priority

  • Severity: S0 - Affects critical data or functionality and leaves users without workaround.
  • Severity: S1 - Affects critical data or functionality and forces users to employ a workaround.
  • Severity: S2 - Affects non-critical data or functionality and forces users to employ a workaround.
  • Severity: S3 - Affects non-critical data or functionality and does not force users to employ a workaround.
  • Severity: S4 - Affects aesthetics, professional look and feel, “quality” or “usability”.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Area: FrameworkComponent: StockIssue: ConfirmedGate 3 Passed. Manual verification of the issue completed. Issue is confirmedPriority: P2A defect with this priority could have functionality issues which are not to expectations.Progress: ready for devReported on 2.4.6-p2Indicates original Magento version for the Issue report.Reproduced on 2.4.xThe issue has been reproduced on latest 2.4-develop branchTriage: Dev.ExperienceIssue related to Developer Experience and needs help with Triage to Confirm or Reject it

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions