提交 f561a87f authored 作者: blu's avatar blu

enhencement: timeout on receive configuration for daemon

上级 4c2aab6c
......@@ -464,6 +464,11 @@ public:
drport = strEnv;
}
strEnv = getenv("LOGV");
if(strEnv != nullptr) {
spdlog::set_level(spdlog::level::debug);
}
strEnv = getenv("PEERID");
if(strEnv != nullptr) {
selfId = strEnv;
......@@ -490,13 +495,17 @@ public:
spdlog::error("evpuller {} failed to setup dealer {}", selfId, addr);
exit(1);
}
spdlog::info("evpuller {} setup dealer to daemon OK", selfId);
ret = zmqhelper::recvConfigMsg(pDaemon, config, addr, selfId);
if(ret != 0) {
spdlog::error("evpuller {} failed to receive configration message {}", selfId, addr);
}
init();
spdlog::info("evpuller {} receive config from daemon OK", selfId);
init();
spdlog::info("evpuller {} init OK", selfId);
thEdgeMsgHandler = thread([this] {
while(true)
{
......
......@@ -171,28 +171,34 @@ int setupDealer(void **ctx, void **s, string addr, string ident, int timeout) {
/// @return 0 success, otherwise failed.
int recvConfigMsg(void *s, json &config, string addr, string ident){
bool bConfigGot = false;
while(!bConfigGot){
auto v = zmqhelper::z_recv_multiple(s);
if(v.size() != 3) {
spdlog::error("{} invalid msg from daemon: {}", ident, addr);
return -1;
auto t = thread([&](){
this_thread::sleep_for(chrono::seconds(5));
if(bConfigGot == false){
spdlog::error("{} failed receive config from evdaemon", ident);
exit(1);
}
});
auto v = zmqhelper::z_recv_multiple(s);
if(v.size() != 3) {
spdlog::error("{} received invalid msg from evdaemon", ident);
exit(1);
}
spdlog::debug("{} configuration msg received: {} {} {}", ident, body2str(v[0]), body2str(v[1]), body2str(v[2]));
try{
string sMeta = json::parse(body2str(v[1]))["type"];
if(sMeta != EV_MSG_META_CONFIG) {
throw StrException("meta type is:" + sMeta + ", but expecting " + EV_MSG_META_CONFIG);
}
config = json::parse(body2str(v[2]));
bConfigGot = true;
}catch(exception &e) {
spdlog::error("{} invalid config msg from daemon {}, {}", ident, addr, e.what());
return -1;
spdlog::debug("{} configuration msg received: {} {} {}", ident, body2str(v[0]), body2str(v[1]), body2str(v[2]));
try{
string sMeta = json::parse(body2str(v[1]))["type"];
if(sMeta != EV_MSG_META_CONFIG) {
throw StrException("meta type is:" + sMeta + ", but expecting " + EV_MSG_META_CONFIG);
}
config = json::parse(body2str(v[2]));
bConfigGot = true;
}catch(exception &e) {
spdlog::error("{} invalid config msg from daemon {}, {}", ident, addr, e.what());
}
return 0;
t.join();
return bConfigGot? 0: -1;
}
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论