[GH-ISSUE #1085] [BUG] Unable to delete archived tasks #2543

Open
opened 2026-03-15 20:49:41 +03:00 by kerem · 1 comment
Owner

Originally created by @Heachy on GitHub (Nov 26, 2025).
Original GitHub issue: https://github.com/hibiken/asynq/issues/1085

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

Describe the bug
Unable to delete archived tasks retrieved from ListArchivedTasks.

Environment (please complete the following information):

  • OS: MacOS,
  • asynq package version v0.25.1
  • Redis/Valkey version 5.0.12

To Reproduce
Steps to reproduce the behavior (Code snippets if applicable):

  1. I used ListArchivedTasks to retrieve archived tasks,and then iterated through them to delete each one.
  2. It returned the error "asynq: FAILED_PRECONDITION: cannot delete task in active state. use CancelProcessing instead," indicating that the task is still active. But the tasks I retrieved were archived tasks, and in debug mode, I can see that the task being deleted has State=TaskStateArchived (5), which is indeed the archived state.

Expected behavior
Success to delete archived tasks retrieved from ListArchivedTasks.

Screenshots
If applicable, add screenshots to help explain your problem.

Additional context
the function
`func (uc *ClusterOpUsecase) cleanArchivedTasks(ctx context.Context) {

for {
	page := 1
	pageSize := 100
	tasks, err := uc.taskManager.GetInspector().ListArchivedTasks(task.QueueCritical, asynq.Page(page), asynq.PageSize(pageSize))
	if err != nil {
		log.Fatal(err)
	}

	for _, taskInfo := range tasks {
		taskId, err := strconv.ParseUint(string(taskInfo.Payload), 10, 64)
		if err != nil {
			continue
		}

		err = uc.taskManager.GetInspector().DeleteTask(task.QueueCritical, taskInfo.ID)
		if err != nil {
			uc.logger.WithContext(ctx).Errorf("delete archived task failed: %s", err)
		}
	}
	time.Sleep(1 * time.Minute)
}

}`

Originally created by @Heachy on GitHub (Nov 26, 2025). Original GitHub issue: https://github.com/hibiken/asynq/issues/1085 Originally assigned to: @hibiken, @kamikazechaser on GitHub. **Describe the bug** Unable to delete archived tasks retrieved from ListArchivedTasks. **Environment (please complete the following information):** - OS: MacOS, - `asynq` package version v0.25.1 - Redis/Valkey version 5.0.12 **To Reproduce** Steps to reproduce the behavior (Code snippets if applicable): 1. I used ListArchivedTasks to retrieve archived tasks,and then iterated through them to delete each one. 2. It returned the error "asynq: FAILED_PRECONDITION: cannot delete task in active state. use CancelProcessing instead," indicating that the task is still active. But the tasks I retrieved were archived tasks, and in debug mode, I can see that the task being deleted has State=TaskStateArchived (5), which is indeed the archived state. **Expected behavior** Success to delete archived tasks retrieved from ListArchivedTasks. **Screenshots** If applicable, add screenshots to help explain your problem. **Additional context** the function `func (uc *ClusterOpUsecase) cleanArchivedTasks(ctx context.Context) { for { page := 1 pageSize := 100 tasks, err := uc.taskManager.GetInspector().ListArchivedTasks(task.QueueCritical, asynq.Page(page), asynq.PageSize(pageSize)) if err != nil { log.Fatal(err) } for _, taskInfo := range tasks { taskId, err := strconv.ParseUint(string(taskInfo.Payload), 10, 64) if err != nil { continue } err = uc.taskManager.GetInspector().DeleteTask(task.QueueCritical, taskInfo.ID) if err != nil { uc.logger.WithContext(ctx).Errorf("delete archived task failed: %s", err) } } time.Sleep(1 * time.Minute) } }`
Author
Owner

@jeffphp commented on GitHub (Dec 19, 2025):

I had the same problem. The underlying cause was that I'm using a Managed Redis Service, which closes idle Redis connection after 5 minutes. By default, Redis Client uses connections forever. When it fails during a transaction, it seems that it happens that the Queue gets corrupted.

I now use Redis.UniversalClient driver with these additional settings and now I don't have these issues anymore:
https://github.com/hibiken/asynq/issues/764#issuecomment-3611269765

<!-- gh-comment-id:3674110222 --> @jeffphp commented on GitHub (Dec 19, 2025): I had the same problem. The underlying cause was that I'm using a Managed Redis Service, which closes idle Redis connection after 5 minutes. By default, Redis Client uses connections forever. When it fails during a transaction, it seems that it happens that the Queue gets corrupted. I now use Redis.UniversalClient driver with these additional settings and now I don't have these issues anymore: https://github.com/hibiken/asynq/issues/764#issuecomment-3611269765
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#2543
No description provided.