[GH-ISSUE #584] [BUG] Unable to pass context using EnqueueContext. #281

Closed
opened 2026-03-02 05:20:09 +03:00 by kerem · 1 comment
Owner

Originally created by @divnoorkang on GitHub (Dec 8, 2022).
Original GitHub issue: https://github.com/hibiken/asynq/issues/584

Originally assigned to: @hibiken on GitHub.

Describe the bug
My context contains some data that i need to access in my workers. I am trying to pass the context using EnqueueContext function provided. Though this function is creating its own context, and my original context is lost somewhere in the process of dequeuing.
Correct context is being carrier till this point, post this not able to find anything.

To Reproduce

  1. Run redis in cluster mode
  2. Enqueue task with a custom context with added fields
    Screenshot 2022-12-08 at 5 02 00 PM
  3. Using HandleFunc(task_name, dequeuer_func)
  4. Signature of the dequeuer function looks like -> dequeuer_func(ctx context.Context, task *asynq.Task) error {}
  5. Reading ctx inside this function gives altogether a new context.

Attaching images of context passed
Enqueued
and received
Dequeued

Expected behavior
Context must be same as the one passed

Environment (please complete the following information):

  • OS: MacOs
  • asynq verison v0.20.0
Originally created by @divnoorkang on GitHub (Dec 8, 2022). Original GitHub issue: https://github.com/hibiken/asynq/issues/584 Originally assigned to: @hibiken on GitHub. **Describe the bug** My context contains some data that i need to access in my workers. I am trying to pass the context using EnqueueContext function provided. Though this function is creating its own context, and my original context is lost somewhere in the process of dequeuing. Correct context is being carrier till [this point](https://github.com/hibiken/asynq/blob/master/internal/rdb/rdb.go#L115), post this not able to find anything. **To Reproduce** 1. Run redis in cluster mode 2. Enqueue task with a custom context with added fields ![Screenshot 2022-12-08 at 5 02 00 PM](https://user-images.githubusercontent.com/77618528/206436199-a53508f7-482f-4734-9787-665ad7f778f2.png) 3. Using HandleFunc(task_name, dequeuer_func) 4. Signature of the dequeuer function looks like -> dequeuer_func(ctx context.Context, task *asynq.Task) error {} 5. Reading ctx inside this function gives altogether a new context. Attaching images of context passed ![Enqueued](https://user-images.githubusercontent.com/77618528/206438213-d41fd687-f0ee-4ade-a15e-9fe6e1564a8e.png) and received ![Dequeued](https://user-images.githubusercontent.com/77618528/206438226-52dd0561-0563-4a45-bd9a-21ce1b8e9e88.png) **Expected behavior** Context must be same as the one passed **Environment (please complete the following information):** - OS: MacOs - asynq verison v0.20.0
kerem 2026-03-02 05:20:09 +03:00
  • closed this issue
  • added the
    bug
    label
Author
Owner

@hibiken commented on GitHub (Dec 19, 2022):

Ah this may be a documentation bug. The feature is working as intended.

As it mentioned in the API doc , the first argument "ctx" applied to the enqueue operation. The content of context is not serialized and passed the worker process.

If you need to provide data to the worker, please use the payload of the task instead.

<!-- gh-comment-id:1358332621 --> @hibiken commented on GitHub (Dec 19, 2022): Ah this may be a documentation bug. The feature is working as intended. As it mentioned in [the API doc ](https://pkg.go.dev/github.com/hibiken/asynq#Client.EnqueueContext), the first argument "ctx" applied to the enqueue operation. The content of context is not serialized and passed the worker process. If you need to provide data to the worker, please use the payload of the task instead.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/asynq#281
No description provided.