When I restart my memcached server, libmemcached never reconnects as long as I'm continuously trying to send data to it. If the client stops activity for a few seconds then starts sending again, the reconnection happens just fine.
It turns out to be a problem with how next_rety is set. Even when we don't try to connect because it's too soon, we still update next_retry.
That's because the socket is invalid, so the server state is MEMCACHED_SERVER_STATE_NEW, not MEMCACHED_SERVER_STATE_IN_TIMEOUT. memcached_mark_server_for_timeout() only skips updating next_retry in the latter state, not the former.
I'm not sure what the right solution is here. Maybe make memcached_quit_server() idempotent by checking for MEMCACHED_SERVER_STATE_NEW or fd == INVALID_SOCKET at the start and returing right away? I'm reluctant to do the same in memcached_mark_server_for_timeout(), in case that skips setting it when we really do need to set it.
When I restart my memcached server, libmemcached never reconnects as long as I'm continuously trying to send data to it. If the client stops activity for a few seconds then starts sending again, the reconnection happens just fine.
It turns out to be a problem with how next_rety is set. Even when we don't try to connect because it's too soon, we still update next_retry.
That's because the socket is invalid, so the server state is MEMCACHED_ SERVER_ STATE_NEW, not MEMCACHED_ SERVER_ STATE_IN_ TIMEOUT. memcached_ mark_server_ for_timeout( ) only skips updating next_retry in the latter state, not the former.
I'm not sure what the right solution is here. Maybe make memcached_ quit_server( ) idempotent by checking for MEMCACHED_ SERVER_ STATE_NEW or fd == INVALID_SOCKET at the start and returing right away? I'm reluctant to do the same in memcached_ mark_server_ for_timeout( ), in case that skips setting it when we really do need to set it.