From 48eb41654859e6130c82c46400b529f2af9ce908 Mon Sep 17 00:00:00 2001 From: FredWH Date: Mon, 28 Jun 2021 14:46:25 +0800 Subject: [PATCH] db_redis: fix broken pipe issue, if redis server with timeout setting. - issue #2764 (cherry picked from commit 7cec977f8e12bbeb0309d903e02461d1ccbf41a8) --- src/modules/db_redis/redis_connection.c | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/modules/db_redis/redis_connection.c b/src/modules/db_redis/redis_connection.c index ad2921f1d57..dd421a78440 100644 --- a/src/modules/db_redis/redis_connection.c +++ b/src/modules/db_redis/redis_connection.c @@ -305,7 +305,8 @@ void *db_redis_command_argv(km_redis_con_t *con, redis_key_t *query) { LM_DBG("query has %d args\n", argc); redisReply *reply = redisCommandArgv(con->con, argc, (const char**)argv, NULL); - if (con->con->err == REDIS_ERR_EOF) { + if (con->con->err != REDIS_OK) { + LM_DBG("redis connection is gone, try reconnect. (%d:%s)\n", con->con->err, con->con->errstr); if (db_redis_connect(con) != 0) { LM_ERR("Failed to reconnect to redis db\n"); pkg_free(argv); @@ -344,7 +345,8 @@ int db_redis_append_command_argv(km_redis_con_t *con, redis_key_t *query, int qu // this should actually never happen, because if all replies // are properly consumed for the previous command, it won't send // out a new query until redisGetReply is called - if (con->con->err == REDIS_ERR_EOF) { + if (con->con->err != REDIS_OK) { + LM_DBG("redis connection is gone, try reconnect. (%d:%s)\n", con->con->err, con->con->errstr); if (db_redis_connect(con) != 0) { LM_ERR("Failed to reconnect to redis db\n"); pkg_free(argv); @@ -374,8 +376,8 @@ int db_redis_get_reply(km_redis_con_t *con, void **reply) { *reply = NULL; ret = redisGetReply(con->con, reply); - if (con->con->err == REDIS_ERR_EOF) { - LM_DBG("redis connection is gone, try reconnect\n"); + if (con->con->err != REDIS_OK) { + LM_DBG("redis connection is gone, try reconnect. (%d:%s)\n", con->con->err, con->con->errstr); con->append_counter = 0; if (db_redis_connect(con) != 0) { LM_ERR("Failed to reconnect to redis db\n"); @@ -396,7 +398,7 @@ int db_redis_get_reply(km_redis_con_t *con, void **reply) { db_redis_key_free(&query); } ret = redisGetReply(con->con, reply); - if (con->con->err != REDIS_ERR_EOF) { + if (con->con->err == REDIS_OK) { con->append_counter--; } } else {