Skip to content

Fix nil panic in memoryUsageCmd Lua script#1092

Open
NilPuig wants to merge 1 commit intohibiken:masterfrom
NilPuig:fix/memory-usage-nil-guard
Open

Fix nil panic in memoryUsageCmd Lua script#1092
NilPuig wants to merge 1 commit intohibiken:masterfrom
NilPuig:fix/memory-usage-nil-guard

Conversation

@NilPuig
Copy link
Copy Markdown

@NilPuig NilPuig commented Feb 7, 2026

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

MEMORY USAGE returns nil for keys that no longer exist (e.g., expired
or deleted task keys). In Lua, nil is converted to false (a boolean).
The 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 the /api/queues endpoint in asynqmon, showing "Could not
retrieve queues live data" in the UI.

The fix adds nil guards around all three MEMORY USAGE calls on task
keys, and a divide-by-zero guard on agg_task_sample_size.

Tested in production with Redis 7.2 and asynq v0.25.1 worker.

Fixes hibiken#728
Related to hibiken#901
@codecov
Copy link
Copy Markdown

codecov bot commented Feb 8, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 63.34%. Comparing base (4f00f52) to head (2fd155e).
⚠️ Report is 34 commits behind head on master.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #1092      +/-   ##
==========================================
- Coverage   67.13%   63.34%   -3.80%     
==========================================
  Files          29       29              
  Lines        4300     4984     +684     
==========================================
+ Hits         2887     3157     +270     
- Misses       1135     1549     +414     
  Partials      278      278              

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@kamikazechaser kamikazechaser added ready-to-merge bug Something isn't working pr-bugfix and removed bug Something isn't working labels Feb 10, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[FEATURE REQUEST] Ignore error on calculating RDB.MemoryUsage

2 participants