memcached_instance_st *server;
memcached_return_t read_ret = MEMCACHED_SUCCESS;
bool connection_failures = false;
+ bool timeouts = false;
while ((server = memcached_io_get_readable_server(ptr, read_ret))) {
char buffer[MEMCACHED_DEFAULT_COMMAND_SIZE];
*error = memcached_response(server, buffer, sizeof(buffer), result);
} else if (*error == MEMCACHED_CONNECTION_FAILURE) {
connection_failures = true;
continue;
+ } else if (*error == MEMCACHED_TIMEOUT) {
+ timeouts = true;
} else if (*error == MEMCACHED_SUCCESS) {
result->count++;
return result;
that.
*/
*error = MEMCACHED_CONNECTION_FAILURE;
+ } else if (timeouts) {
+ *error = MEMCACHED_TIMEOUT;
} else if (*error == MEMCACHED_SUCCESS) {
*error = MEMCACHED_END;
} else if (result->count == 0) {
set(ENV{INVALID_CONFIGURATION} 1)
endif()
+add_executable(timeout timeout.c)
+
file(GLOB_RECURSE TESTING_SRC RELATIVE ${CMAKE_CURRENT_SOURCE_DIR} *.cpp)
set(TESTING_ROOT "${CMAKE_CURRENT_BINARY_DIR}")
set(SOURCES_ROOT "${CMAKE_SOURCE_DIR}")
endif()
endif()
-add_dependencies(runtests ${CLIENTS})
+add_dependencies(runtests ${CLIENTS} timeout)
if(TARGET memaslap)
configure_set(HAVE_MEMASLAP 1)
add_dependencies(runtests memaslap)
--- /dev/null
+#include "test/lib/common.hpp"
+#include "test/lib/random.hpp"
+#include "test/lib/Server.hpp"
+#include "test/lib/ReturnMatcher.hpp"
+
+TEST_CASE("memcached_regression_lp1540680") {
+ Server timeout{TESTING_ROOT "/timeout", {"-p", random_port_string}};
+ MemcachedPtr memc;
+ LoneReturnMatcher test{*memc};
+
+ REQUIRE(timeout.start());
+ this_thread::sleep_for(500ms);
+
+ REQUIRE_SUCCESS(memcached_server_add(*memc, "localhost", get<int>(timeout.getSocketOrPort())));
+
+ memcached_return_t rc;
+ Malloced val(memcached_get(*memc, S("not-found"), nullptr, nullptr, &rc));
+ REQUIRE_RC(MEMCACHED_TIMEOUT, rc);
+ REQUIRE_FALSE(*val);
+}
--- /dev/null
+#include <unistd.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <memory.h>
+#include <arpa/inet.h>
+#include <sys/socket.h>
+
+// $0 -u nobody -p <port>
+int main(int argc, char **argv) {
+ short port = argc == 5 ? atoi(argv[4]) : 11211;
+ struct sockaddr_in servaddr;
+ memset(&servaddr, 0, sizeof(struct sockaddr_in));
+
+ servaddr.sin_family = AF_INET;
+ servaddr.sin_addr.s_addr = htons(INADDR_ANY);
+ servaddr.sin_port = htons(port);
+
+ int listen_fd = socket(AF_INET, SOCK_STREAM, 0);
+ bind(listen_fd, (struct sockaddr *) &servaddr, sizeof(servaddr));
+ listen(listen_fd, 10);
+ printf("Listening (%d) on port %d\n", listen_fd, port);
+
+ int comm_fd = accept(listen_fd, NULL, NULL);
+ printf("Connection (%d) accepted, now do nothing...\n", comm_fd);
+
+ pause();
+}