[GH-ISSUE #987] Task always retry when canceled #2501

Open
opened 2026-03-15 20:43:17 +03:00 by kerem · 2 comments
Owner

Originally created by @thedmdim on GitHub (Dec 16, 2024).
Original GitHub issue: https://github.com/hibiken/asynq/issues/987

Originally assigned to: @hibiken, @kamikazechaser on GitHub.

Hi everyone!

I need to cancel my task without retry. I call CancelProcessing for this.
CancelProcessing calls task's cancel function. At my handler I do this:

select {
		case <-ctx.Done():
			return asynq.SkipRetry
		case:
				...
}

But this does no effect as far as at processor.go at

select {
			case <-p.abort:
				// time is up, push the message back to queue and quit this worker goroutine.
				p.logger.Warnf("Quitting worker. task id=%s", msg.ID)
				p.requeue(lease, msg)
				return
			case <-lease.Done():
				cancel()
				p.handleFailedMessage(ctx, lease, msg, ErrLeaseExpired)
				return
			case <-ctx.Done():
				p.handleFailedMessage(ctx, lease, msg, ctx.Err())
				return
			case resErr := <-resCh:
				if resErr != nil {
					p.handleFailedMessage(ctx, lease, msg, resErr)
					return
				}
				p.handleSucceededMessage(lease, msg)
}

case <-ctx.Done() read from channel occurs before case resErr := <-resCh

And due to this we have no opportunity to skip retry when publish cancelation, is this right?

Originally created by @thedmdim on GitHub (Dec 16, 2024). Original GitHub issue: https://github.com/hibiken/asynq/issues/987 Originally assigned to: @hibiken, @kamikazechaser on GitHub. Hi everyone! I need to cancel my task without retry. I call `CancelProcessing` for this. `CancelProcessing` calls task's `cancel` function. At my handler I do this: ```go select { case <-ctx.Done(): return asynq.SkipRetry case: ... } ``` But this does no effect as far as at `processor.go` at ```go select { case <-p.abort: // time is up, push the message back to queue and quit this worker goroutine. p.logger.Warnf("Quitting worker. task id=%s", msg.ID) p.requeue(lease, msg) return case <-lease.Done(): cancel() p.handleFailedMessage(ctx, lease, msg, ErrLeaseExpired) return case <-ctx.Done(): p.handleFailedMessage(ctx, lease, msg, ctx.Err()) return case resErr := <-resCh: if resErr != nil { p.handleFailedMessage(ctx, lease, msg, resErr) return } p.handleSucceededMessage(lease, msg) } ``` `case <-ctx.Done()` read from channel occurs before `case resErr := <-resCh` And due to this we have no opportunity to skip retry when publish cancelation, is this right?
Author
Owner

@kamikazechaser commented on GitHub (Dec 16, 2024):

Possibly the same as #968

<!-- gh-comment-id:2545621036 --> @kamikazechaser commented on GitHub (Dec 16, 2024): Possibly the same as #968
Author
Owner

@thedmdim commented on GitHub (Dec 16, 2024):

Fixed this at #988

<!-- gh-comment-id:2546249046 --> @thedmdim commented on GitHub (Dec 16, 2024): Fixed this at #988
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#2501
No description provided.