From d5c71a0f672e940613a533f3b50368fed41e7b41 Mon Sep 17 00:00:00 2001 From: Nathan Wang Date: Mon, 11 Sep 2023 10:28:57 -0700 Subject: [PATCH 1/2] check try lock return value --- example/plugins/c-api/protocol/Protocol.cc | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/example/plugins/c-api/protocol/Protocol.cc b/example/plugins/c-api/protocol/Protocol.cc index 469bc762565..4f816f8e63a 100644 --- a/example/plugins/c-api/protocol/Protocol.cc +++ b/example/plugins/c-api/protocol/Protocol.cc @@ -26,6 +26,8 @@ #include "tscore/ink_defs.h" #include +#define RETRY_TIME 10 + /* global variable */ TSTextLogObject protocol_plugin_log; @@ -54,10 +56,16 @@ accept_handler(TSCont contp, TSEvent event, void *edata) /* This is no reason for not grabbing the lock. So skip the routine which handle LockTry failure case. */ - TSMutexLockTry(pmutex); // TODO: why should it not check if we got the lock?? + + // check if grabbing the lock is successful + if (TSMutexLockTry(pmutex) != TS_SUCCESS) { + TSDebug(PLUGIN_NAME, "Unable to get lock. Will retry after some time"); + TSContScheduleOnPool(contp, RETRY_TIME, TS_THREAD_POOL_NET); + break; + } + TSContCall(txn_sm, TS_EVENT_NONE, nullptr); TSMutexUnlock(pmutex); - break; default: /* Something wrong with the network, if there are any From 24c247bdc1c0b0d5b6268cebf3615211ee9a2030 Mon Sep 17 00:00:00 2001 From: Nathan Wang Date: Mon, 11 Sep 2023 11:00:33 -0700 Subject: [PATCH 2/2] add break statement to prevent fallthrough --- example/plugins/c-api/protocol/Protocol.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/example/plugins/c-api/protocol/Protocol.cc b/example/plugins/c-api/protocol/Protocol.cc index 4f816f8e63a..b47efb9c139 100644 --- a/example/plugins/c-api/protocol/Protocol.cc +++ b/example/plugins/c-api/protocol/Protocol.cc @@ -63,9 +63,9 @@ accept_handler(TSCont contp, TSEvent event, void *edata) TSContScheduleOnPool(contp, RETRY_TIME, TS_THREAD_POOL_NET); break; } - TSContCall(txn_sm, TS_EVENT_NONE, nullptr); TSMutexUnlock(pmutex); + break; default: /* Something wrong with the network, if there are any