perf: Async Redis Connection Handling to Prevent Main Thread Blocking#15303
perf: Async Redis Connection Handling to Prevent Main Thread Blocking#15303medhaRachel wants to merge 3 commits into
Conversation
Fix ID: 8e4966bb-bfcb-4088-8188-d51d27a721df Anomaly Type: latency_spike The original code performs synchronous redisConnect() calls on the main execution thread, which can cause significant latency spikes when network operations take longer than expected. The fix implements non-blocking connection handling using redisConnectNonBlock() and redisGetReply() with proper error handling to prevent the main thread from being blocked during network operations. Generated by OptimaCore AI Performance Intelligence
|
|
Fix ID: 8e4966bb-bfcb-4088-8188-d51d27a721df Anomaly Type: latency_spike The original code performs synchronous redisConnect() calls on the main execution thread, which can cause significant latency spikes when network operations take longer than expected. The fix implements non-blocking connection handling using redisConnectNonBlock() and redisGetReply() with proper error handling to prevent the main thread from being blocked during network operations. Generated by OptimaCore AI Performance Intelligence
|
Hi, I’m Jit, a friendly security platform designed to help developers build secure applications from day zero with an MVS (Minimal viable security) mindset. In case there are security findings, they will be communicated to you as a comment inside the PR. Hope you’ll enjoy using Jit. Questions? Comments? Want to learn more? Get in touch with us. |
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
Reviewed by Cursor Bugbot for commit 261f5d2. Configure here.
| FD_ZERO(&write_fds); | ||
| FD_SET(fd, &write_fds); | ||
|
|
||
| if (select(fd + 1, NULL, &write_fds, NULL, &timeout) > 0 && FD_ISSET(fd, &write_fds)) { |
There was a problem hiding this comment.
Uses socket before connect errors
High Severity
After redisConnectNonBlock, the code only checks for a null context. Hiredis can return a non-null context with err set and fd still REDIS_INVALID_FD (e.g. DNS or early connect failure). The code then calls FD_SET and select on that fd, which is undefined behavior and can crash or mis-handle the failure.
Reviewed by Cursor Bugbot for commit 261f5d2. Configure here.


Note
Low Risk
Isolated benchmark helper using standard non-blocking connect completion; no auth, persistence, or server core changes.
Overview
Adds
getRedisContextinredis-benchmark.cto obtain a hiredisredisContextwithout a fully blocking connect: it usesredisConnectNonBlock, then waits up to 1 second withselecton the socket’s write readiness, confirms success viagetsockopt(SO_ERROR), and **redisFree**s the context on timeout or connect failure.This matches the goal of avoiding indefinite blocking on connect while still returning a ready context (or
NULL) for benchmark use.Reviewed by Cursor Bugbot for commit 261f5d2. Bugbot is set up for automated code reviews on this repo. Configure here.