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

enhencement: timeout on receive configuration for daemon

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