[PR #1092] Fix nil panic in memoryUsageCmd Lua script #3032

Open
opened 2026-03-15 21:16:31 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/hibiken/asynq/pull/1092
Author: @NilPuig
Created: 2/7/2026
Status: 🔄 Open

Base: masterHead: fix/memory-usage-nil-guard


📝 Commits (1)

  • 2fd155e Fix nil guard for MEMORY USAGE in memoryUsageCmd Lua script

📊 Changes

1 file changed (+14 additions, -6 deletions)

View changed files

📝 internal/rdb/inspect.go (+14 -6)

📄 Description

Summary

MEMORY USAGE returns nil for Redis keys that no longer exist (e.g., expired or deleted task keys). In Lua, nil is converted to false (a boolean). The memoryUsageCmd script then attempts arithmetic on this boolean value, causing:

ERR user_script:30: attempt to perform arithmetic on local 'bytes' (a boolean value)

This breaks Inspector.GetQueueInfo() and the /api/queues endpoint in asynqmon, showing "Could not retrieve queues live data" in the UI.

Changes

  • Add nil guards around all three MEMORY USAGE calls on task keys (lines 266, 283, 306)
  • Add divide-by-zero guard on agg_task_sample_size for the aggregation group section

How to reproduce

This happens when task keys referenced in a queue's pending/active/scheduled/retry lists have expired or been deleted from Redis, but the list entries still reference them. MEMORY USAGE on a non-existent key returns nil, which becomes false in Lua.

Testing

Tested in production with Redis 7.2.4 and asynq v0.25.1 worker processing ~900K tasks/day. After applying this patch, the /api/queues endpoint returns data correctly.

Fixes #728
Related to #901


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/hibiken/asynq/pull/1092 **Author:** [@NilPuig](https://github.com/NilPuig) **Created:** 2/7/2026 **Status:** 🔄 Open **Base:** `master` ← **Head:** `fix/memory-usage-nil-guard` --- ### 📝 Commits (1) - [`2fd155e`](https://github.com/hibiken/asynq/commit/2fd155e31da91ecbe2d3f3f8475eee485805cd41) Fix nil guard for MEMORY USAGE in memoryUsageCmd Lua script ### 📊 Changes **1 file changed** (+14 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `internal/rdb/inspect.go` (+14 -6) </details> ### 📄 Description ## Summary `MEMORY USAGE` returns nil for Redis keys that no longer exist (e.g., expired or deleted task keys). In Lua, nil is converted to `false` (a boolean). The `memoryUsageCmd` script then attempts arithmetic on this boolean value, causing: ``` ERR user_script:30: attempt to perform arithmetic on local 'bytes' (a boolean value) ``` This breaks `Inspector.GetQueueInfo()` and the `/api/queues` endpoint in asynqmon, showing "Could not retrieve queues live data" in the UI. ## Changes - Add nil guards around all three `MEMORY USAGE` calls on task keys (lines 266, 283, 306) - Add divide-by-zero guard on `agg_task_sample_size` for the aggregation group section ## How to reproduce This happens when task keys referenced in a queue's pending/active/scheduled/retry lists have expired or been deleted from Redis, but the list entries still reference them. `MEMORY USAGE` on a non-existent key returns nil, which becomes `false` in Lua. ## Testing Tested in production with Redis 7.2.4 and asynq v0.25.1 worker processing ~900K tasks/day. After applying this patch, the `/api/queues` endpoint returns data correctly. Fixes #728 Related to #901 --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
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#3032
No description provided.