Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 58b9a03

Browse filesBrowse files
dgpetrieappkins
authored andcommitted
client::re_auth submits 2 AUTH commands upon reconnect, expects only one response (#15)
* Allow 64bit ints for TTL in client. Redis server supports 64 bit ints for TTL. Actually up to 0x7FFFFFFFFFFFFFFFLL milliseconds. Or 0x7FFFFFFFFFFFFFFFLL/1000 seconds. * If we lose the TCP conenction and it is then reconnected, there was a problem were the AUTH command got serialized twice to the buffer to be sent to the TCP connection by unprotected_auth: Once when it was directly added to the buffer AND Once because it was added to the command queue it got serialize to the buffer again However there was only one call back on the command queue. So we got 2 responces and only one callback to handle them. So the next command in the queue gets the second AUTH response instead of the expected responce and everything is off by one.
1 parent 7dfa42d commit 58b9a03
Copy full SHA for 58b9a03

File tree

Expand file treeCollapse file tree

1 file changed

+10
-2
lines changed
Filter options
Expand file treeCollapse file tree

1 file changed

+10
-2
lines changed

‎sources/core/client.cpp

Copy file name to clipboardExpand all lines: sources/core/client.cpp
+10-2Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,13 +398,21 @@ namespace cpp_redis {
398398
return;
399399
}
400400

401-
unprotected_auth(m_password, [&](cpp_redis::reply &reply) {
401+
// In re_auth we do not want to serialize the command to the TCP buffer (i.e. call m_client.send)
402+
// as it will get serialized to the buffer in resend_failed_commands after re_auth is called in
403+
// reconnect. So we just push the command into the command queue.
404+
//
405+
// Otherwise we will end up with the AUTH command serialized to
406+
// the buffer twice and in the command queue once, which causes a problem when we get 2 responses
407+
// back. The subsequent responses are off by one in the command callbacks.
408+
//
409+
m_commands.push({{"AUTH", m_password}, [&](cpp_redis::reply &reply) {
402410
if (reply.is_string() && reply.as_string() == "OK") {
403411
__CPP_REDIS_LOG(warn, "client successfully re-authenticated");
404412
} else {
405413
__CPP_REDIS_LOG(warn, std::string("client failed to re-authenticate: " + reply.as_string()).c_str());
406414
}
407-
});
415+
}});
408416
}
409417

410418
void

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.