Skip to content

Commit

Permalink
fix bug of flora agent
Browse files Browse the repository at this point in the history
agent may dead block if flora connection broken
  • Loading branch information
张晨 authored and 张晨 committed Jun 21, 2019
1 parent e4e5c6b commit da94b25
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/flora-agent.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,8 +116,8 @@ void Agent::start(bool block) {
}

void Agent::run() {
unique_lock<mutex> locker(conn_mutex);
shared_ptr<Client> cli;
unique_lock<mutex> locker(conn_mutex, defer_lock);
shared_ptr<Client> cli, gabage;
flora::ClientOptions cliopts;

cliopts.bufsize = options.bufsize;
Expand All @@ -131,15 +131,20 @@ void Agent::run() {
KLOGI(TAG,
"connect to flora service %s failed, retry after %u milliseconds",
options.uri.c_str(), options.reconn_interval.count());
locker.lock();
start_cond.notify_one();
conn_cond.wait_for(locker, options.reconn_interval);
} else {
KLOGI(TAG, "flora service %s connected", options.uri.c_str());
init_cli(cli);
flora_cli = cli;
locker.lock();
flora_cli.swap(cli);
start_cond.notify_one();
conn_cond.wait(locker);
gabage.swap(flora_cli);
}
locker.unlock();
gabage.reset();
}
}

Expand Down

0 comments on commit da94b25

Please sign in to comment.