mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 06:38:20 +00:00
Redis: disconnect cleanly if INFO request fails
This commit is contained in:
parent
0d18ce4e13
commit
9f12208f57
2 changed files with 19 additions and 8 deletions
|
@ -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 reply The reply from the server for the command.
|
||||
* @param privdata A pointer to private data passed in the command.
|
||||
*/
|
||||
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);
|
||||
backend->HandleInfoResult(static_cast<redisReply*>(reply));
|
||||
}
|
||||
|
@ -630,8 +630,13 @@ void Redis::HandleInfoResult(redisReply* reply) {
|
|||
}
|
||||
}
|
||||
|
||||
if ( ! connected && res.err_str.empty() )
|
||||
res.err_str = "INFO command did not return server version";
|
||||
if ( ! connected ) {
|
||||
if ( res.err_str.empty() )
|
||||
res.err_str = "INFO command did not return server version";
|
||||
|
||||
disconnect_reason = res.err_str;
|
||||
redisAsyncDisconnect(async_ctx);
|
||||
}
|
||||
|
||||
freeReplyObject(reply);
|
||||
CompleteCallback(open_cb, res);
|
||||
|
@ -678,8 +683,13 @@ void Redis::OnDisconnect(int status) {
|
|||
else {
|
||||
--active_ops;
|
||||
|
||||
EnqueueBackendLost("Client disconnected");
|
||||
CompleteCallback(close_cb, {ReturnCode::SUCCESS});
|
||||
if ( disconnect_reason.empty() )
|
||||
EnqueueBackendLost("Client disconnected");
|
||||
else
|
||||
EnqueueBackendLost(util::fmt("Client disconnected: %s", disconnect_reason.c_str()));
|
||||
|
||||
if ( close_cb )
|
||||
CompleteCallback(close_cb, {ReturnCode::SUCCESS});
|
||||
}
|
||||
|
||||
redisAsyncFree(async_ctx);
|
||||
|
|
|
@ -70,12 +70,13 @@ private:
|
|||
// poll.
|
||||
std::deque<redisReply*> reply_queue;
|
||||
|
||||
OpenResultCallback* open_cb;
|
||||
ResultCallback* close_cb;
|
||||
OpenResultCallback* open_cb = nullptr;
|
||||
ResultCallback* close_cb = nullptr;
|
||||
std::mutex expire_mutex;
|
||||
|
||||
std::string server_addr;
|
||||
std::string key_prefix;
|
||||
std::string disconnect_reason;
|
||||
|
||||
std::atomic<bool> connected = false;
|
||||
std::atomic<bool> expire_running = false;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue