Browse code

db_redis: fix broken pipe issue, if redis server with timeout setting.

- issue #2764

(cherry picked from commit 7cec977f8e12bbeb0309d903e02461d1ccbf41a8)
(cherry picked from commit 48eb41654859e6130c82c46400b529f2af9ce908)
(cherry picked from commit e9272d8d67b9f8f9e04ad511ae014573b0aeb227)

FredWH authored on 28/06/2021 06:46:25 • Henning Westerholt committed on 22/10/2021 12:04:01
Showing 1 changed files
... ...
@@ -279,7 +279,8 @@ void *db_redis_command_argv(km_redis_con_t *con, redis_key_t *query) {
279 279
     LM_DBG("query has %d args\n", argc);
280 280
 
281 281
     redisReply *reply = redisCommandArgv(con->con, argc, (const char**)argv, NULL);
282
-    if (con->con->err == REDIS_ERR_EOF) {
282
+    if (con->con->err != REDIS_OK) {
283
+        LM_DBG("redis connection is gone, try reconnect. (%d:%s)\n", con->con->err, con->con->errstr);
283 284
         if (db_redis_connect(con) != 0) {
284 285
             LM_ERR("Failed to reconnect to redis db\n");
285 286
             pkg_free(argv);
... ...
@@ -318,7 +319,8 @@ int db_redis_append_command_argv(km_redis_con_t *con, redis_key_t *query, int qu
318 319
     // this should actually never happen, because if all replies
319 320
     // are properly consumed for the previous command, it won't send
320 321
     // out a new query until redisGetReply is called
321
-    if (con->con->err == REDIS_ERR_EOF) {
322
+    if (con->con->err != REDIS_OK) {
323
+        LM_DBG("redis connection is gone, try reconnect. (%d:%s)\n", con->con->err, con->con->errstr);
322 324
         if (db_redis_connect(con) != 0) {
323 325
             LM_ERR("Failed to reconnect to redis db\n");
324 326
             pkg_free(argv);
... ...
@@ -348,8 +350,8 @@ int db_redis_get_reply(km_redis_con_t *con, void **reply) {
348 350
 
349 351
     *reply = NULL;
350 352
     ret = redisGetReply(con->con, reply);
351
-    if (con->con->err == REDIS_ERR_EOF) {
352
-        LM_DBG("redis connection is gone, try reconnect\n");
353
+    if (con->con->err != REDIS_OK) {
354
+        LM_DBG("redis connection is gone, try reconnect. (%d:%s)\n", con->con->err, con->con->errstr);
353 355
         con->append_counter = 0;
354 356
         if (db_redis_connect(con) != 0) {
355 357
             LM_ERR("Failed to reconnect to redis db\n");
... ...
@@ -370,7 +372,7 @@ int db_redis_get_reply(km_redis_con_t *con, void **reply) {
370 372
             db_redis_key_free(&query);
371 373
         }
372 374
         ret = redisGetReply(con->con, reply);
373
-        if (con->con->err != REDIS_ERR_EOF) {
375
+        if (con->con->err == REDIS_OK) {
374 376
             con->append_counter--;
375 377
         }
376 378
     } else {