From 946a0fdf1c4ddb5482fc9c510decff23c28f1e86 Mon Sep 17 00:00:00 2001 From: Brian Aker Date: Mon, 7 Jun 2010 14:06:53 -0700 Subject: [PATCH] Fix (though only partial), for connect timeout. --- libmemcached/connect.c | 4 +++- libmemcached/memcached.h | 2 +- tests/mem_functions.c | 29 +++++++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 2 deletions(-) diff --git a/libmemcached/connect.c b/libmemcached/connect.c index 8d0e0a9b..b17400ab 100644 --- a/libmemcached/connect.c +++ b/libmemcached/connect.c @@ -316,7 +316,7 @@ static memcached_return_t network_connect(memcached_server_st *ptr) fds[0].events = POLLOUT; int timeout= ptr->root->connect_timeout; - if (ptr->root->flags.no_block == false) + if (ptr->root->flags.no_block == true) timeout= -1; size_t loop_max= 5; @@ -330,6 +330,8 @@ static memcached_return_t network_connect(memcached_server_st *ptr) loop_max= 1; break; case 0: + if (loop_max==1) + return MEMCACHED_TIMEOUT; continue; // A real error occurred and we need to completely bail default: diff --git a/libmemcached/memcached.h b/libmemcached/memcached.h index 26f101f2..a7cdc977 100644 --- a/libmemcached/memcached.h +++ b/libmemcached/memcached.h @@ -72,7 +72,7 @@ struct memcached_st { bool cork:1; bool hash_with_prefix_key:1; bool ketama_weighted:1; - bool no_block:1; + bool no_block:1; // Don't block bool no_reply:1; bool randomize_replica_read:1; bool reuse_memory:1; diff --git a/tests/mem_functions.c b/tests/mem_functions.c index 11d7219b..ba99c0be 100644 --- a/tests/mem_functions.c +++ b/tests/mem_functions.c @@ -5860,6 +5860,34 @@ static test_return_t regression_bug_490486(memcached_st *memc) return TEST_SUCCESS; } +static test_return_t regression_bug_583031(memcached_st *unused) +{ + (void)unused; + + memcached_st *memc= memcached_create(NULL); + assert(memc); + memcached_server_add(memc, "10.2.3.4", 11211); + + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_CONNECT_TIMEOUT, 1000); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RETRY_TIMEOUT, 1000); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SND_TIMEOUT, 1000); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_RCV_TIMEOUT, 1000); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_POLL_TIMEOUT, 1000); + memcached_behavior_set(memc, MEMCACHED_BEHAVIOR_SERVER_FAILURE_LIMIT, 3); + + memcached_return_t rc; + size_t length; + uint32_t flags; + + (void)memcached_get(memc, "dsf", 3, &length, &flags, &rc); + + test_true(rc == MEMCACHED_TIMEOUT); + + memcached_free(memc); + + return TEST_SUCCESS; +} + static void memcached_die(memcached_st* mc, memcached_return error, const char* what, uint32_t it) { fprintf(stderr, "Iteration #%u: ", it); @@ -6171,6 +6199,7 @@ test_st regression_tests[]= { {"lp:447342", 1, (test_callback_fn)regression_bug_447342 }, {"lp:463297", 1, (test_callback_fn)regression_bug_463297 }, {"lp:490486", 1, (test_callback_fn)regression_bug_490486 }, + {"lp:583031", 1, (test_callback_fn)regression_bug_583031 }, {"lp:?", 1, (test_callback_fn)regression_bug_ }, {0, 0, (test_callback_fn)0} }; -- 2.30.2