Skip to content

Commit b138ff9

Browse files
kcudnikyxieca
authored andcommitted
Notify OA about exception and process only restart query events (#437)
1 parent 0974a43 commit b138ff9

File tree

1 file changed

+44
-35
lines changed

1 file changed

+44
-35
lines changed

syncd/syncd.cpp

+44-35
Original file line numberDiff line numberDiff line change
@@ -119,10 +119,7 @@ bool isInitViewMode()
119119

120120
bool g_veryFirstRun = false;
121121

122-
void exit_and_notify(int status) __attribute__ ((__noreturn__));
123-
124-
void exit_and_notify(
125-
_In_ int status)
122+
void notify_OA_about_syncd_exception()
126123
{
127124
SWSS_LOG_ENTER();
128125

@@ -147,20 +144,6 @@ void exit_and_notify(
147144
{
148145
SWSS_LOG_ERROR("Unknown runtime error");
149146
}
150-
151-
if (options.disableExitSleep)
152-
{
153-
exit(status);
154-
}
155-
156-
SWSS_LOG_WARN("sleep forever to keep data plane active");
157-
158-
while (true)
159-
{
160-
sleep(UINT_MAX);
161-
162-
SWSS_LOG_NOTICE("sleep ended, sleeping again");
163-
}
164147
}
165148

166149
void sai_diag_shell(
@@ -2395,8 +2378,7 @@ sai_status_t handle_bulk_generic(
23952378
}
23962379
else
23972380
{
2398-
SWSS_LOG_ERROR("api %d is not supported in bulk route", api);
2399-
exit_and_notify(EXIT_FAILURE);
2381+
SWSS_LOG_THROW("api %d is not supported in bulk route", api);
24002382
}
24012383

24022384
if (status != SAI_STATUS_SUCCESS)
@@ -2472,8 +2454,7 @@ sai_status_t processBulkEvent(
24722454

24732455
if (isInitViewMode())
24742456
{
2475-
SWSS_LOG_ERROR("bulk api (%d) is not supported in init view mode", api);
2476-
exit_and_notify(EXIT_FAILURE);
2457+
SWSS_LOG_THROW("bulk api (%d) is not supported in init view mode", api);
24772458
}
24782459

24792460
if (api != SAI_COMMON_API_BULK_GET)
@@ -2500,17 +2481,14 @@ sai_status_t processBulkEvent(
25002481
break;
25012482

25022483
default:
2503-
SWSS_LOG_ERROR("bulk api for %s is not supported yet, FIXME",
2484+
SWSS_LOG_THROW("bulk api for %s is not supported yet, FIXME",
25042485
sai_serialize_object_type(object_type).c_str());
2505-
exit_and_notify(EXIT_FAILURE);
25062486
}
25072487

25082488
if (status != SAI_STATUS_SUCCESS)
25092489
{
2510-
SWSS_LOG_ERROR("failed to execute bulk api: %s",
2490+
SWSS_LOG_THROW("failed to execute bulk api: %s",
25112491
sai_serialize_status(status).c_str());
2512-
2513-
exit_and_notify(EXIT_FAILURE);
25142492
}
25152493

25162494
return status;
@@ -3667,6 +3645,10 @@ int syncd_main(int argc, char **argv)
36673645
sai_switch_api_t *sai_switch_api = NULL;
36683646
sai_api_query(SAI_API_SWITCH, (void**)&sai_switch_api);
36693647

3648+
volatile bool runMainLoop = true;
3649+
3650+
std::shared_ptr<swss::Select> s = std::make_shared<swss::Select>();
3651+
36703652
try
36713653
{
36723654
SWSS_LOG_NOTICE("before onSyncdStart");
@@ -3681,16 +3663,32 @@ int syncd_main(int argc, char **argv)
36813663

36823664
SWSS_LOG_NOTICE("syncd listening for events");
36833665

3684-
std::shared_ptr<swss::Select> s = std::make_shared<swss::Select>();
3685-
36863666
s->addSelectable(asicState.get());
36873667
s->addSelectable(restartQuery.get());
36883668
s->addSelectable(flexCounter.get());
36893669
s->addSelectable(flexCounterGroup.get());
36903670

36913671
SWSS_LOG_NOTICE("starting main loop");
3672+
}
3673+
catch(const std::exception &e)
3674+
{
3675+
SWSS_LOG_ERROR("Runtime error during syncd init: %s", e.what());
3676+
3677+
notify_OA_about_syncd_exception();
36923678

3693-
while(true)
3679+
s = std::make_shared<swss::Select>();
3680+
3681+
s->addSelectable(restartQuery.get());
3682+
3683+
SWSS_LOG_NOTICE("starting main loop, ONLY restart query");
3684+
3685+
if (options.disableExitSleep)
3686+
runMainLoop = false;
3687+
}
3688+
3689+
while(runMainLoop)
3690+
{
3691+
try
36943692
{
36953693
swss::Selectable *sel = NULL;
36963694

@@ -3719,6 +3717,7 @@ int syncd_main(int argc, char **argv)
37193717
if (shutdownType != SYNCD_RESTART_TYPE_PRE_SHUTDOWN)
37203718
{
37213719
// break out the event handling loop to shutdown syncd
3720+
runMainLoop = false;
37223721
break;
37233722
}
37243723

@@ -3788,12 +3787,22 @@ int syncd_main(int argc, char **argv)
37883787
processEvent(*(swss::ConsumerTable*)sel);
37893788
}
37903789
}
3791-
}
3792-
catch(const std::exception &e)
3793-
{
3794-
SWSS_LOG_ERROR("Runtime error: %s", e.what());
3790+
catch(const std::exception &e)
3791+
{
3792+
SWSS_LOG_ERROR("Runtime error: %s", e.what());
3793+
3794+
notify_OA_about_syncd_exception();
37953795

3796-
exit_and_notify(EXIT_FAILURE);
3796+
s = std::make_shared<swss::Select>();
3797+
3798+
s->addSelectable(restartQuery.get());
3799+
3800+
if (options.disableExitSleep)
3801+
runMainLoop = false;
3802+
3803+
// make sure that if second exception will arise, then we break the loop
3804+
options.disableExitSleep = true;
3805+
}
37973806
}
37983807

37993808
if (shutdownType == SYNCD_RESTART_TYPE_WARM)

0 commit comments

Comments
 (0)