mapleFU commented on code in PR #2461:
URL: https://github.com/apache/kvrocks/pull/2461#discussion_r1701977432
##########
src/server/worker.cc:
##########
@@ -333,18 +338,18 @@ Status Worker::AddConnection(redis::Connection *c) {
redis::Connection *Worker::removeConnection(int fd) {
redis::Connection *conn = nullptr;
- std::unique_lock<std::mutex> lock(conns_mu_);
- auto iter = conns_.find(fd);
- if (iter != conns_.end()) {
- conn = iter->second;
- conns_.erase(iter);
+ std::lock_guard<std::mutex> guard(conns_mu_);
Review Comment:
What brings up my attention is, if we really wants to do like this, can the
critical section looks like:
```
if (ConnMap::accessor accessor; conns_.find(accessor, fd)) {
{
conn = accessor->second;
std::lock_guard<std::mutex> guard(conns_mu_);
conns_.erase(accessor);
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]