Commit 3d0b073e587baece1cb3d639ac356505d93e6e76
1 parent
284c2452
Fix disconnect behavior, when hiredis returns null reply
Call Redox::disconnectCallback from processReply
Showing
5 changed files
with
17 additions
and
6 deletions
README.md
| ... | ... | @@ -272,4 +272,5 @@ then: |
| 272 | 272 | Redox is in its early stages and I am looking for feedback and contributors to make |
| 273 | 273 | it easier, faster, and more robust. Open issues on GitHub or message me directly. |
| 274 | 274 | |
| 275 | -Redox is not currently recommended for production use. It has no support for features like connection pooling, sentinels, clusters, etc. Feel free to provide them! | |
| 275 | +Redox is not currently recommended for production use. It has no support for features like | |
| 276 | +connection pooling, sentinels, clusters, etc. Feel free to provide them! | ... | ... |
include/redox/client.hpp
| ... | ... | @@ -368,6 +368,10 @@ private: |
| 368 | 368 | // give it access to private members |
| 369 | 369 | template<class ReplyT> |
| 370 | 370 | friend void Command<ReplyT>::free(); |
| 371 | + | |
| 372 | + // Access to call disconnectedCallback | |
| 373 | + template<class ReplyT> | |
| 374 | + friend void Command<ReplyT>::processReply(redisReply* r); | |
| 371 | 375 | }; |
| 372 | 376 | |
| 373 | 377 | // ------------------------------------------------ | ... | ... |
src/client.cpp
| ... | ... | @@ -136,7 +136,7 @@ void Redox::disconnectedCallback(const redisAsyncContext* ctx, int status) { |
| 136 | 136 | Redox* rdx = (Redox*) ctx->data; |
| 137 | 137 | |
| 138 | 138 | if (status != REDIS_OK) { |
| 139 | - rdx->logger_.error() << "Could not disconnect from Redis: " << ctx->errstr; | |
| 139 | + rdx->logger_.error() << "Disconnected from Redis on error: " << ctx->errstr; | |
| 140 | 140 | rdx->connect_state_ = DISCONNECT_ERROR; |
| 141 | 141 | } else { |
| 142 | 142 | rdx->logger_.info() << "Disconnected from Redis as planned."; | ... | ... |
src/command.cpp
| ... | ... | @@ -53,9 +53,15 @@ void Command<ReplyT>::processReply(redisReply* r) { |
| 53 | 53 | |
| 54 | 54 | reply_obj_ = r; |
| 55 | 55 | |
| 56 | - reply_guard_.lock(); | |
| 57 | - parseReplyObject(); | |
| 58 | - reply_guard_.unlock(); | |
| 56 | + if(reply_obj_ == nullptr) { | |
| 57 | + reply_status_ = ERROR_REPLY; | |
| 58 | + logger_.error() << "Received null redisReply* from hiredis."; | |
| 59 | + Redox::disconnectedCallback(rdx_->ctx_, REDIS_ERR); | |
| 60 | + | |
| 61 | + } else { | |
| 62 | + lock_guard<mutex> lg(reply_guard_); | |
| 63 | + parseReplyObject(); | |
| 64 | + } | |
| 59 | 65 | |
| 60 | 66 | invoke(); |
| 61 | 67 | ... | ... |
src/utils/logger.cpp
| ... | ... | @@ -75,7 +75,7 @@ const tm *Logger::getLocalTime() { |
| 75 | 75 | |
| 76 | 76 | void Logger::log(Level l, std::string oMessage) { |
| 77 | 77 | const static char *LevelStr[] = { |
| 78 | - "[Trace] ", "[Debug] ", "[Info] ", "[Warning]", "[Error] ", "[Severe] " | |
| 78 | + "[Trace] ", "[Debug] ", "[Info] ", "[Warning]", "[Error] ", "[Fatal] " | |
| 79 | 79 | }; |
| 80 | 80 | |
| 81 | 81 | m_lock.lock(); | ... | ... |