Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Never reconnect after connection reset (binary protocol) #12

Closed
m6w6 opened this issue Jan 20, 2020 · 2 comments
Closed

Never reconnect after connection reset (binary protocol) #12

m6w6 opened this issue Jan 20, 2020 · 2 comments

Comments

@m6w6
Copy link
Collaborator

m6w6 commented Jan 20, 2020

Imported from Launchpad using lp2gh.


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 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.

@m6w6 m6w6 added the New label Jan 20, 2020
@m6w6
Copy link
Collaborator Author

m6w6 commented Jan 20, 2020


Simply checking for MEMCACHED_SERVER_STATE_NEW in memcached_quit_server() won't work, because it's already in MEMCACHED_SERVER_STATE_IN_TIMEOUT.

Perhaps the problem is in memcached_send_binary. memcached_send_ascii has different logic here. When it writes the header, if we don't want a reply or flush we return right away. Otherwise, we only call memcached_io_reset if the return code is MEMCACHED_WRITE_FAILURE. Should the binary protocl use the same behavior? Perhaps there's a refactoring where we can write the logic once and use it for both the binary and ascii protocols, but that can be left to another time.

@m6w6
Copy link
Collaborator Author

m6w6 commented Jan 20, 2020


Follows the behavior of the ascii send.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant