Re-insert xmon requests if we fail to write them

This commit is contained in:
Francesco Mazzoli
2023-07-18 16:11:01 +00:00
parent 6973ed9ff7
commit dce2961d7f
2 changed files with 15 additions and 8 deletions

View File

@@ -201,7 +201,8 @@ reconnect:
// send all requests
if (gotHeartbeat) {
_agent->getRequests(requests);
for (const auto& req: requests) {
for (int i = 0; i < requests.size(); i++) {
const auto& req = requests[i];
if (req.msgType == XmonRequestType::CREATE) {
LOG_DEBUG(_env, "creating alert, aid=%s binnable=%s message=%s", req.alertId, req.binnable, req.message);
} else if (req.msgType == XmonRequestType::UPDATE) {
@@ -213,6 +214,12 @@ reconnect:
}
packRequest(buf, req);
errString = buf.writeOut(sock);
if (unlikely(!errString.empty())) {
// re-insert all the requests
for (int j = i; j < requests.size(); j++) {
_agent->addRequest(std::move(requests[j]));
}
}
CHECK_ERR_STRING(errString);
LOG_DEBUG(_env, "sent request to xmon");
}