Skip to content

message's Context doesn't save when a worker fetch the message in v3 #196

@FitzBogard

Description

@FitzBogard
func (c *Consumer) worker(ctx context.Context, workerID int32) {
	var lock *redislock.Lock
	defer func() {
		if lock != nil {
			_ = lock.Release(ctx)
		}
	}()

	timer := time.NewTimer(time.Minute)
	timer.Stop()

	for {
		if workerID >= atomic.LoadInt32(&c.numWorker) {
			return
		}
		if c.opt.WorkerLimit > 0 {
			lock = c.lockWorker(ctx, lock, workerID)
		}

		msg := c.waitMessage(ctx, timer)
		if msg == nil {
			if atomic.LoadInt32(&c.state) >= stateStoppingWorkers {
				return
			}
			continue
		}

                msg.Ctx = ctx // this place
		_ = c.Process(msg)
	}
}

if we use consumer's context, we will not use the redis queue's message's context, it's a specified context which definited by the sdk users, it may contains some their own context's value, so I think it's better to remove the line "msg.Ctx = ctx", let users use their context.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions