Repository: pinpoint-apm/pinpoint-c-agent (language: python)

Issue:
pinpoint_force_end_trace() will stuck in infinite loop if node is E_INVALID_NODE
**Describe the bug**
Function `pinpoint_force_end_trace()` defined [here](https://github.com/pinpoint-apm/pinpoint-c-agent/blob/62559d4224a4ebc74d66a21a1fe8b6cbead4bd14/common/src/common.cpp#L248) keep calling `pinpoint_end_trace()` until `E_ROOT_NODE` is received. The logic doesn't consider that `pinpoint_end_trace()` can also output `E_INVALID_NODE` and make `pinpoint_force_end_trace()` stuck in infinite loop.


**To Reproduce**
Steps to reproduce the behavior:
1. Execute `pinpoint_force_end_trace()` for invalid node

**Actual behavior**
* Agent stuck in infinite loop

**Expected behavior**
* Output failure and agent should not stuck

**Agent Version:**
v0.4.11





Discussion / hints:
@sillidev 

Thanks, we will check this case.

Fix patch:
diff --git a/common/src/common.cpp b/common/src/common.cpp
index 3381473a2..451f9499d 100644
--- a/common/src/common.cpp
+++ b/common/src/common.cpp
@@ -253,6 +253,8 @@ int pinpoint_force_end_trace(NodeID id, int32_t timeout)
         while (id != E_ROOT_NODE)
         {
             id = pinpoint_end_trace(id);
+            if (id == E_INVALID_NODE)
+                break;
         }
         // back to normal
         _span_timeout = global_agent_info.timeout_ms;


Test patch:
diff --git a/common/test/test_common.cc b/common/test/test_common.cc
index 20d073bc4..1c5d517cc 100644
--- a/common/test/test_common.cc
+++ b/common/test/test_common.cc
@@ -163,6 +163,12 @@ TEST(common, force_end_trace)
     EXPECT_NE(id, 0);
     int ret = pinpoint_force_end_trace(id, 300);
     EXPECT_EQ(ret, 0);
+    id = NodeID(809999);
+    pinpoint_force_end_trace(id, 300);
+    pinpoint_force_end_trace(NodeID(-1235), 300);
+    pinpoint_force_end_trace(NodeID(0), 300);
+    pinpoint_force_end_trace(NodeID(1), 300);
+    pinpoint_force_end_trace(NodeID(-1), 300);
 }
 
 TEST(common, version)