Fixed unhandled promise rejection in Redis adapter _get timeout path#27007
Fixed unhandled promise rejection in Redis adapter _get timeout path#27007muratcorlu wants to merge 5 commits into
Conversation
When getTimeoutMilliseconds was configured, _get wrapped the cache read in a new Promise but did not handle rejections from the inner cache.get() call. If Redis rejected the command (e.g. with enableOfflineQueue: false), the rejection went unhandled, which crashes Ghost. Fixed by adding a .catch() that clears the timeout and resolves with null, treating a Redis error during a timed get as a cache miss.
codeCraft-Ritik
left a comment
There was a problem hiding this comment.
Great catch! Handling unhandled rejections in this scenario is really important for stability
WalkthroughThe 🚥 Pre-merge checks | ✅ 3✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
ghost/core/core/server/adapters/lib/redis/AdapterCacheRedis.js (1)
184-187: Consider logging the swallowed error for observability.The fix correctly prevents the unhandled rejection, but silently swallowing the error may complicate debugging Redis connectivity issues. Elsewhere in this file, errors are consistently logged via
logging.error(err). Consider at least a debug-level log here to maintain observability.🔧 Proposed fix to add debug logging
- }).catch(() => { + }).catch((err) => { + debug('get', key, 'error', err.message); clearTimeout(timer); resolve(null); });🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@ghost/core/core/server/adapters/lib/redis/AdapterCacheRedis.js` around lines 184 - 187, The catch block currently swallows the Redis error (catch(() => { clearTimeout(timer); resolve(null); })), losing observability; change it to capture the error (catch(err) or catch(error)) and log it via the same logger used elsewhere (e.g., logging.error(error) or logging.debug(error)) before clearing the timeout and resolving null so failures are recorded; update the catch in AdapterCacheRedis.js where timer is cleared and resolve(null) is called to include the logging call.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@ghost/core/core/server/adapters/lib/redis/AdapterCacheRedis.js`:
- Around line 184-187: The catch block currently swallows the Redis error
(catch(() => { clearTimeout(timer); resolve(null); })), losing observability;
change it to capture the error (catch(err) or catch(error)) and log it via the
same logger used elsewhere (e.g., logging.error(error) or logging.debug(error))
before clearing the timeout and resolving null so failures are recorded; update
the catch in AdapterCacheRedis.js where timer is cleared and resolve(null) is
called to include the logging call.
ℹ️ Review info
⚙️ Run configuration
Configuration used: Path: .coderabbit.yaml
Review profile: CHILL
Plan: Pro
Run ID: 5026d771-028d-47ea-934a-c643b4eef37d
📒 Files selected for processing (2)
ghost/core/core/server/adapters/lib/redis/AdapterCacheRedis.jsghost/core/test/unit/server/adapters/lib/redis/adapter-cache-redis.test.js
codeCraft-Ritik
left a comment
There was a problem hiding this comment.
Great fix! Handling unhandled Redis rejections is critical for system stability
|
|
No more relevant with latest changes, closing this. |



When getTimeoutMilliseconds was configured, _get wrapped the cache read in a new Promise but did not handle rejections from the inner cache.get() call. If Redis rejected the command (e.g. with enableOfflineQueue: false), the rejection went unhandled, which crashes Ghost.
Fixed by adding a .catch() that clears the timeout and resolves with null, treating a Redis error during a timed get as a cache miss.
Got some code for us? Awesome 🎊!
Please take a minute to explain the change you're making:
Please check your PR against these items:
We appreciate your contribution! 🙏