提交 4a2331f9 authored 作者: blu's avatar blu

potential bugfix: reverse tunnel timeout for avoiding dead threads

上级 aa6de6e9
...@@ -477,7 +477,7 @@ private: ...@@ -477,7 +477,7 @@ private:
if(peerId == "evcloudsvc") { if(peerId == "evcloudsvc") {
zmqhelper::z_send(pDealer, peerId, body[2], body[3]); zmqhelper::z_send(pDealer, peerId, body[2], body[3]);
} }
else{ else {
vector<vector<uint8_t> >v = {body[1], body[0], body[2], body[3]}; vector<vector<uint8_t> >v = {body[1], body[0], body[2], body[3]};
if(peerData["status"].count(peerId) != 0 && peerData["status"][peerId] != 0 && this->peerData["status"][peerId][peerId] != -1) { if(peerData["status"].count(peerId) != 0 && peerData["status"][peerId] != 0 && this->peerData["status"][peerId][peerId] != -1) {
spdlog::info("evdaemon {} route msg from {} to {}", devSn, selfId, peerId); spdlog::info("evdaemon {} route msg from {} to {}", devSn, selfId, peerId);
...@@ -545,7 +545,8 @@ private: ...@@ -545,7 +545,8 @@ private:
} }
int manageReverseTun(bool bStart, json &tunCfg) { int manageReverseTun(bool bStart, json &tunCfg)
{
int ret = 0; int ret = 0;
if(tunCfg.count("port") == 0 || tunCfg.count("host") == 0 || tunCfg.count("user") == 0 || tunCfg.count("password") == 0) { if(tunCfg.count("port") == 0 || tunCfg.count("host") == 0 || tunCfg.count("user") == 0 || tunCfg.count("password") == 0) {
spdlog::error("evcdaemon {} invalid reverse tunnel settings, shall have host, port, user, password fields"); spdlog::error("evcdaemon {} invalid reverse tunnel settings, shall have host, port, user, password fields");
...@@ -554,7 +555,7 @@ private: ...@@ -554,7 +555,7 @@ private:
thread th; thread th;
string host = tunCfg["host"], user = tunCfg["user"], password = tunCfg["password"]; string host = tunCfg["host"], user = tunCfg["user"], password = tunCfg["password"];
int port = tunCfg["port"]; int port = tunCfg["port"];
th = thread([host, port, user, password](){ th = thread([host, port, user, password]() {
createReverseTun(host, port, user, password); createReverseTun(host, port, user, password);
}); });
...@@ -631,7 +632,8 @@ private: ...@@ -631,7 +632,8 @@ private:
if(v.size() == 1) { if(v.size() == 1) {
if(data["metaValue"] == EV_MSG_META_VALUE_CMD_REVESETUN) { if(data["metaValue"] == EV_MSG_META_VALUE_CMD_REVESETUN) {
manageReverseTun(true, data["data"]); manageReverseTun(true, data["data"]);
}else{ }
else {
spdlog::info("evdaemon {} received msg {} from cloud to itself. but has no implementation for", devSn, data.dump()); spdlog::info("evdaemon {} received msg {} from cloud to itself. but has no implementation for", devSn, data.dump());
} }
} }
...@@ -690,7 +692,8 @@ private: ...@@ -690,7 +692,8 @@ private:
return 0; return 0;
} }
void setUpDealer(){ void setUpDealer()
{
lock_guard<mutex> lg(mutHeartBeat); lock_guard<mutex> lg(mutHeartBeat);
if(pDealer != nullptr) { if(pDealer != nullptr) {
int i = 0; int i = 0;
...@@ -906,8 +909,8 @@ public: ...@@ -906,8 +909,8 @@ public:
thCloud.detach(); thCloud.detach();
spdlog::info("evdaemon {} cloud message processor had setup {}", devSn, cloudAddr); spdlog::info("evdaemon {} cloud message processor had setup {}", devSn, cloudAddr);
thHeartBeat = thread([this](){ thHeartBeat = thread([this]() {
while(true){ while(true) {
{ {
lock_guard<mutex> lg(this->mutHeartBeat); lock_guard<mutex> lg(this->mutHeartBeat);
if(this->pDealer != nullptr) if(this->pDealer != nullptr)
......
...@@ -141,7 +141,8 @@ error_exit: ...@@ -141,7 +141,8 @@ error_exit:
auto body = z_recv_multiple(pDealer,false); auto body = z_recv_multiple(pDealer,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", this->devSn, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", this->devSn, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleCloudMsg(body); this->handleCloudMsg(body);
} }
......
...@@ -494,11 +494,12 @@ private: ...@@ -494,11 +494,12 @@ private:
factor = int(int(this->pps) / this->detPara.fpsProc); // regulator to 0 if it was set inresonably high factor = int(int(this->pps) / this->detPara.fpsProc); // regulator to 0 if it was set inresonably high
} }
if(factor != 0 ){ if(factor != 0 ) {
if(called % factor == 0) { if(called % factor == 0) {
proc = true; proc = true;
//factor = 0; // reset it open to change //factor = 0; // reset it open to change
}else{ }
else {
proc = false; proc = false;
} }
} }
...@@ -508,8 +509,9 @@ private: ...@@ -508,8 +509,9 @@ private:
spdlog::info("evmlmotion {} pps {}, fpsFactor {}, called {}, lag {}, skip processing", this->selfId, this->pps, factor, called, this->pktLag); spdlog::info("evmlmotion {} pps {}, fpsFactor {}, called {}, lag {}, skip processing", this->selfId, this->pps, factor, called, this->pktLag);
} }
// detectMotion(pCodecContext->pix_fmt, pFrame, false); // detectMotion(pCodecContext->pix_fmt, pFrame, false);
}else{ }
if((called % (180*4)) == 0){ else {
if((called % (180*4)) == 0) {
spdlog::info("evmlmotion {} pps {}, fpsFactor {}, called {}, lag {}", this->selfId, this->pps, factor, called, this->pktLag); spdlog::info("evmlmotion {} pps {}, fpsFactor {}, called {}, lag {}", this->selfId, this->pps, factor, called, this->pktLag);
} }
detectMotion(pCodecContext->pix_fmt, pFrame, detect); detectMotion(pCodecContext->pix_fmt, pFrame, detect);
...@@ -816,7 +818,8 @@ protected: ...@@ -816,7 +818,8 @@ protected:
meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR; meta["value"] = EV_MSG_META_VALUE_REPORT_LEVEL_ERROR;
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump()); z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
spdlog::error(msg); spdlog::error(msg);
}else{ }
else {
if(!bStatsSent) { if(!bStatsSent) {
bStatsSent = true; bStatsSent = true;
string msg = fmt::format("evmlmotion {} successfully decode packet", selfId); string msg = fmt::format("evmlmotion {} successfully decode packet", selfId);
...@@ -901,7 +904,8 @@ public: ...@@ -901,7 +904,8 @@ public:
auto body = z_recv_multiple(pDaemon,false); auto body = z_recv_multiple(pDaemon,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleCloudMsg(body); this->handleCloudMsg(body);
} }
...@@ -915,7 +919,8 @@ public: ...@@ -915,7 +919,8 @@ public:
auto body = z_recv_multiple(pDealer,false); auto body = z_recv_multiple(pDealer,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleEdgeMsg(body); this->handleEdgeMsg(body);
} }
......
...@@ -327,7 +327,8 @@ protected: ...@@ -327,7 +327,8 @@ protected:
spdlog::error(msg); spdlog::error(msg);
// TODO: message report to cloud // TODO: message report to cloud
exit(1); exit(1);
}else{ }
else {
string msg = fmt::format("evpuller {} successfully openned input stream {}", selfId, urlIn); string msg = fmt::format("evpuller {} successfully openned input stream {}", selfId, urlIn);
json meta; json meta;
json data; json data;
...@@ -411,7 +412,7 @@ protected: ...@@ -411,7 +412,7 @@ protected:
pktCnt++; pktCnt++;
packet.stream_index = streamList[packet.stream_index]; packet.stream_index = streamList[packet.stream_index];
// skip first 5 packets avoid pusher and slicer exception // skip first 5 packets avoid pusher and slicer exception
if(pktCnt <= 5){ if(pktCnt <= 5) {
if(pktCnt == 5) { if(pktCnt == 5) {
// serialize formatctx to bytes // serialize formatctx to bytes
// be attention to the scope of lock guard! // be attention to the scope of lock guard!
...@@ -501,7 +502,8 @@ public: ...@@ -501,7 +502,8 @@ public:
auto body = z_recv_multiple(pDealer,false); auto body = z_recv_multiple(pDealer,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
string msg; string msg;
for(auto &v: body) { for(auto &v: body) {
...@@ -524,7 +526,8 @@ public: ...@@ -524,7 +526,8 @@ public:
auto body = z_recv_multiple(pDaemon,false); auto body = z_recv_multiple(pDaemon,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleCloudMsg(body); this->handleCloudMsg(body);
} }
......
...@@ -306,8 +306,7 @@ private: ...@@ -306,8 +306,7 @@ private:
AVDictionary *pOptsRemux = nullptr; AVDictionary *pOptsRemux = nullptr;
string proto = urlOut.substr(0, 4); string proto = urlOut.substr(0, 4);
int cnt = 0; int cnt = 0;
while(ret < 0) while(ret < 0) {
{
if(cnt > 3) { if(cnt > 3) {
string msg = fmt::format("evpusher {} failed to write output header \"{}\": {}, {}", selfId, urlOut, ret, av_err2str(ret)); string msg = fmt::format("evpusher {} failed to write output header \"{}\": {}, {}", selfId, urlOut, ret, av_err2str(ret));
json meta; json meta;
...@@ -405,7 +404,8 @@ private: ...@@ -405,7 +404,8 @@ private:
z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump()); z_send(pDaemon, "evcloudsvc", meta.dump(), data.dump());
spdlog::error(msg); spdlog::error(msg);
exit(1); exit(1);
}else{ }
else {
string msg = fmt::format("evpusher {} successfully open output \"{}\"", selfId, urlOut); string msg = fmt::format("evpusher {} successfully open output \"{}\"", selfId, urlOut);
json meta; json meta;
json data; json data;
...@@ -557,8 +557,9 @@ protected: ...@@ -557,8 +557,9 @@ protected:
pktCnt = 0; pktCnt = 0;
continue; continue;
} }
}else{ }
if(!bStatsSent){ else {
if(!bStatsSent) {
bStatsSent = true; bStatsSent = true;
string msg = fmt::format("evpusher {} start pushing {}", selfId, urlOut); string msg = fmt::format("evpusher {} start pushing {}", selfId, urlOut);
json meta; json meta;
...@@ -626,7 +627,8 @@ public: ...@@ -626,7 +627,8 @@ public:
auto body = z_recv_multiple(pDaemon,false); auto body = z_recv_multiple(pDaemon,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleCloudMsg(body); this->handleCloudMsg(body);
} }
...@@ -640,7 +642,8 @@ public: ...@@ -640,7 +642,8 @@ public:
auto body = z_recv_multiple(pDealer,false); auto body = z_recv_multiple(pDealer,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleEdgeMsg(body); this->handleEdgeMsg(body);
} }
......
...@@ -613,7 +613,8 @@ protected: ...@@ -613,7 +613,8 @@ protected:
pktCnt = 0; pktCnt = 0;
break; break;
} }
}else{ }
else {
if(!bStatsSent) { if(!bStatsSent) {
bStatsSent = true; bStatsSent = true;
string msg = fmt::format("evslicer {} starting write file", selfId); string msg = fmt::format("evslicer {} starting write file", selfId);
...@@ -911,7 +912,8 @@ public: ...@@ -911,7 +912,8 @@ public:
auto body = z_recv_multiple(pDealer,false); auto body = z_recv_multiple(pDealer,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple edge msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
handleEdgeMsg(body); handleEdgeMsg(body);
} }
...@@ -926,7 +928,8 @@ public: ...@@ -926,7 +928,8 @@ public:
auto body = z_recv_multiple(pDaemon,false); auto body = z_recv_multiple(pDaemon,false);
if(body.size() == 0) { if(body.size() == 0) {
spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno())); spdlog::error("evslicer {} failed to receive multiple cloud msg: {}", selfId, zmq_strerror(zmq_errno()));
}else{ }
else {
// full proto msg received. // full proto msg received.
this->handleCloudMsg(body); this->handleCloudMsg(body);
} }
......
...@@ -119,6 +119,9 @@ int createReverseTun(string host, int port, string user, string _password) ...@@ -119,6 +119,9 @@ int createReverseTun(string host, int port, string user, string _password)
closeFun(); return -1; closeFun(); return -1;
} }
// bugfix: timeout
libssh2_session_set_timeout( session, 15 * 1000);
/* At this point we havn't yet authenticated. The first thing to do /* At this point we havn't yet authenticated. The first thing to do
* is check the hostkey's fingerprint against our known hosts Your app * is check the hostkey's fingerprint against our known hosts Your app
* may have it hard coded, may go to a file, may present it to the * may have it hard coded, may go to a file, may present it to the
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论