Skip to content

Commit

Permalink
Fix orchagent hang problem caused by erase operation on empty map (#348)
Browse files Browse the repository at this point in the history
Signed-off-by: Jipan Yang <[email protected]>
  • Loading branch information
jipanyang authored and lguohan committed Oct 17, 2017
1 parent e5164f9 commit a4022e2
Showing 1 changed file with 21 additions and 6 deletions.
27 changes: 21 additions & 6 deletions orchagent/switchorch.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,22 +43,24 @@ void SwitchOrch::doTask(Consumer &consumer)

if (op == SET_COMMAND)
{
bool retry = false;

for (auto i : kfvFieldsValues(t))
{
auto attribute = fvField(i);

if (switch_attribute_map.find(attribute) == switch_attribute_map.end())
{
SWSS_LOG_ERROR("Unsupported switch attribute %s", attribute.c_str());
it = consumer.m_toSync.erase(it);
continue;
break;
}

auto value = fvValue(i);

sai_attribute_t attr;
attr.id = switch_attribute_map.at(attribute);

bool invalid_attr = false;
switch (attr.id)
{
case SAI_SWITCH_ATTR_FDB_UNICAST_MISS_PACKET_ACTION:
Expand All @@ -67,8 +69,8 @@ void SwitchOrch::doTask(Consumer &consumer)
if (packet_action_map.find(value) == packet_action_map.end())
{
SWSS_LOG_ERROR("Unsupported packet action %s", value.c_str());
it = consumer.m_toSync.erase(it);
continue;
invalid_attr = true;
break;
}
attr.value.s32 = packet_action_map.at(value);
break;
Expand All @@ -79,19 +81,32 @@ void SwitchOrch::doTask(Consumer &consumer)
break;

default:
invalid_attr = true;
break;
}
if (invalid_attr)
{
/* break from kfvFieldsValues for loop */
break;
}

sai_status_t status = sai_switch_api->set_switch_attribute(gSwitchId, &attr);
if (status != SAI_STATUS_SUCCESS)
{
SWSS_LOG_ERROR("Failed to set switch attribute %s to %s, rv:%d",
attribute.c_str(), value.c_str(), status);
it++;
continue;
retry = true;
break;
}

SWSS_LOG_NOTICE("Set switch attribute %s to %s", attribute.c_str(), value.c_str());
}
if (retry == true)
{
it++;
}
else
{
it = consumer.m_toSync.erase(it);
}
}
Expand Down

0 comments on commit a4022e2

Please sign in to comment.