Redis: disconnect cleanly if INFO request fails

This commit is contained in:
Tim Wojtulewicz 2025-05-30 07:48:43 -07:00
parent 0d18ce4e13
commit 9f12208f57
2 changed files with 19 additions and 8 deletions

View file

@ -124,14 +124,14 @@ void redisGeneric(redisAsyncContext* ctx, void* reply, void* privdata) {
} }
/** /**
* Callback handler for ZADD commands. * Callback handler for INFO commands.
* *
* @param ctx The async context that called this callback. * @param ctx The async context that called this callback.
* @param reply The reply from the server for the command. * @param reply The reply from the server for the command.
* @param privdata A pointer to private data passed in the command. * @param privdata A pointer to private data passed in the command.
*/ */
void redisINFO(redisAsyncContext* ctx, void* reply, void* privdata) { void redisINFO(redisAsyncContext* ctx, void* reply, void* privdata) {
auto t = Tracer("generic"); auto t = Tracer("info");
auto backend = static_cast<zeek::storage::backend::redis::Redis*>(ctx->data); auto backend = static_cast<zeek::storage::backend::redis::Redis*>(ctx->data);
backend->HandleInfoResult(static_cast<redisReply*>(reply)); backend->HandleInfoResult(static_cast<redisReply*>(reply));
} }
@ -630,9 +630,14 @@ void Redis::HandleInfoResult(redisReply* reply) {
} }
} }
if ( ! connected && res.err_str.empty() ) if ( ! connected ) {
if ( res.err_str.empty() )
res.err_str = "INFO command did not return server version"; res.err_str = "INFO command did not return server version";
disconnect_reason = res.err_str;
redisAsyncDisconnect(async_ctx);
}
freeReplyObject(reply); freeReplyObject(reply);
CompleteCallback(open_cb, res); CompleteCallback(open_cb, res);
} }
@ -678,7 +683,12 @@ void Redis::OnDisconnect(int status) {
else { else {
--active_ops; --active_ops;
if ( disconnect_reason.empty() )
EnqueueBackendLost("Client disconnected"); EnqueueBackendLost("Client disconnected");
else
EnqueueBackendLost(util::fmt("Client disconnected: %s", disconnect_reason.c_str()));
if ( close_cb )
CompleteCallback(close_cb, {ReturnCode::SUCCESS}); CompleteCallback(close_cb, {ReturnCode::SUCCESS});
} }

View file

@ -70,12 +70,13 @@ private:
// poll. // poll.
std::deque<redisReply*> reply_queue; std::deque<redisReply*> reply_queue;
OpenResultCallback* open_cb; OpenResultCallback* open_cb = nullptr;
ResultCallback* close_cb; ResultCallback* close_cb = nullptr;
std::mutex expire_mutex; std::mutex expire_mutex;
std::string server_addr; std::string server_addr;
std::string key_prefix; std::string key_prefix;
std::string disconnect_reason;
std::atomic<bool> connected = false; std::atomic<bool> connected = false;
std::atomic<bool> expire_running = false; std::atomic<bool> expire_running = false;