Skip to content

Commit

Permalink
Fix data race in SetCurrentConnection (apache#440)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinxiao authored and ShooterIT committed Jan 27, 2022
1 parent a29d30b commit 08c3e0b
Showing 1 changed file with 5 additions and 1 deletion.
6 changes: 5 additions & 1 deletion src/redis_connection.cc
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,6 @@ void Connection::ExecuteCommands(const std::vector<Redis::CommandTokens> &to_pro
Config *config = svr_->GetConfig();
std::string reply, password = config->requirepass;

svr_->SetCurrentConnection(this);
for (auto &cmd_tokens : to_process_cmds) {
if (IsFlagEnabled(Redis::Connection::kCloseAfterReply) &&
!IsFlagEnabled(Connection::kMultiExec)) break;
Expand Down Expand Up @@ -330,6 +329,11 @@ void Connection::ExecuteCommands(const std::vector<Redis::CommandTokens> &to_pro
(config->cluster_enabled && cmd_name == "clusterx" && cmd_tokens.size() >= 2
&& Cluster::SubCommandIsExecExclusive(cmd_tokens[1]))) {
exclusivity = svr_->WorkExclusivityGuard();

// When executing lua script commands that have "exclusive" attribute,
// we need to know current connection, but we should set current connection
// after acquiring the WorkExclusivityGuard to make it thread-safe
svr_->SetCurrentConnection(this);
} else {
concurrency = svr_->WorkConcurrencyGuard();
}
Expand Down

0 comments on commit 08c3e0b

Please sign in to comment.