[Bug] dashboard-api: INCR and EXPIRE in dbExport are not atomic — export quota key can persist without TTL if process crashes
Describe the bug
In apps/dashboard-api/src/controllers/dbExport.controller.js, the daily export quota key is incremented and then given a TTL in two separate Redis operations:
const newCount = await redis.incr(key);
if (newCount === 1) {
await redis.expire(key, 86400);
}
If the Node.js process crashes, is restarted, or loses the Redis connection between the INCR and the EXPIRE calls, the key is created but never given an expiry. The counter for that project/day persists indefinitely, permanently blocking the project from making further export requests on that day — or preventing exports forever if the TTL is never applied.
To Reproduce
- Send an export request that creates the counter key for the first time (
newCount === 1). - Simulate a crash between INCR and EXPIRE (e.g., kill -9 the process, or introduce a mock that throws before EXPIRE).
- Restart the server.
- Send export requests. The key still exists with
value = 1and no TTL, so the limit check passes normally — but if you kill before EXPIRE on every first request, the key has no TTL. - Over multiple days the counter accumulates without resetting.
Expected behavior
The increment and TTL assignment should be atomic. Use SET key 1 EX 86400 NX for the first write, then INCR for subsequent ones. Or use the incrWithTtlAtomic helper already present in @urbackend/common:
const newCount = await incrWithTtlAtomic(redis, key, 86400, 1);
if (newCount > maxExports) {
await redis.decr(key);
return next(new AppError(429, `Daily export limit reached...`));
}
Additional context
File: apps/dashboard-api/src/controllers/dbExport.controller.js
Labels: bug, nsoc26, level2
pls assign this to me under gssoc'26
Hi @yash-pouranik! I am the author of this issue and would like to work on it under GSSoC '26. Could you please assign it to me?
/assign @yash-pouranik /claim
/assign
@coderabbitai Is this a valid issue??
🏁 Script executed: Length of output: 4500 🏁 Script executed: Length of output: 11033🧩 Analysis chain
#!/bin/bash
set -euo pipefail
repo="geturbackend/urBackend"
issue="258"
echo "== Issue =="
gh issue view "$issue" --repo "$repo" --json number,title,body,state,author,labels,assignees,comments,url
echo
echo "== Linked pull requests =="
gh api "repos/$repo/issues/$issue/timeline" \
-H "Accept: application/vnd.github+json" \
--paginate \
--jq '.[] | select(.event == "cross-referenced" or .event == "connected") | {event, source: .source.issue.html_url, title: .source.issue.title, state: .source.issue.state}' || true
#!/bin/bash
set -euo pipefail
controller="apps/dashboard-api/src/controllers/dbExport.controller.js"
echo "== Controller outline =="
ast-grep outline "$controller" --items all || true
echo
echo "== Quota logic in controller =="
rg -n -C 12 -P '\b(redis\.(incr|expire|decr)|maxExports|export.*limit|quota)\b' "$controller" || true
echo
echo "== Atomic helper definitions and usages =="
rg -n -C 8 -P '\bincrWithTtlAtomic\s*\(' . \
-g '!node_modules/**' -g '!dist/**' -g '!build/**' || true
@yash-pouranik, no. Issue #258 is not valid against the current code.
apps/dashboard-api/src/controllers/dbExport.controller.js performs the quota update in one redis.eval() call. Its Lua script runs INCR and the first-key EXPIRE atomically. A Node.js crash cannot occur between those Redis commands.
The issue describes an older implementation with separate client-side INCR and EXPIRE calls. The current implementation already removes that failure window. Close the issue as already fixed or stale.
You are interacting with an AI system.
ok Closing.