From 83c937ae8f33c724a38e0014faa3770ebd48258c Mon Sep 17 00:00:00 2001 From: Hayodea Hekol Date: Fri, 24 Oct 2025 00:46:13 -0400 Subject: [PATCH] LivoxProto1: Cancel async contin branch cbs in oracle fn We were canceling the registered handler CBs in their branch segments instead of in the unifying oracle fn. This caused a bug where handlers were left behind in the udpCmdDemuxer and thus a handler was invoked twice when a UDP msg came in. --- commonLibs/livoxProto1/device.cpp | 27 +++++++++++---------------- 1 file changed, 11 insertions(+), 16 deletions(-) diff --git a/commonLibs/livoxProto1/device.cpp b/commonLibs/livoxProto1/device.cpp index 2375522..2450c46 100644 --- a/commonLibs/livoxProto1/device.cpp +++ b/commonLibs/livoxProto1/device.cpp @@ -625,16 +625,12 @@ private: } } - // This is called from the UDP command handler - void executeHandshakeReq1_2( + void executeHandshakeReq1_2( std::shared_ptr context, const uint8_t* data, ssize_t bytesReceived, const struct sockaddr_in& senderAddr - ) + ) { - // Unregister the handler to decrement refcount - device.unregisterUdpCommandHandler(0x00, 0x01, context->deviceIP); - // Store the received data context->bytesReceived = bytesReceived; context->senderAddr = senderAddr; @@ -661,13 +657,14 @@ private: // Ensure we only execute once using atomic exchange if (handlerExecuted.exchange(true) == true) { return; } + // Cancel timer if still running + timeoutTimer.cancel(); + device.unregisterUdpCommandHandler(0x00, 0x01, deviceIP); + // Examine the flags and decide what happened SocketState finalSocketState = socketState.load(); bool finalTimerFired = timerFired.load(); - // Cancel timer if still running - timeoutTimer.cancel(); - // Check for timeout only if there was no socket activity if (finalTimerFired && finalSocketState == SocketState::SOCKET_STILL_WAITING) @@ -1371,12 +1368,8 @@ protected: std::shared_ptr> context, const uint8_t* data, ssize_t bytesReceived, const struct sockaddr_in& senderAddr - ) + ) { - // Unregister the handler to decrement refcount - device.unregisterUdpCommandHandler( - 0x00, 0x04, device.discoveredDevice.ipAddr); - // Store the received data context->bytesReceived = bytesReceived; context->senderAddr = senderAddr; @@ -1405,11 +1398,13 @@ protected: // Only execute once if (context->handlerExecuted.exchange(true)) { return; } + context->timeoutTimer.cancel(); + device.unregisterUdpCommandHandler( + 0x00, 0x04, device.discoveredDevice.ipAddr); + SocketState finalSocketState = context->socketState.load(); bool finalTimerFired = context->timerFired.load(); - context->timeoutTimer.cancel(); - if (finalTimerFired && finalSocketState == SocketState::SOCKET_STILL_WAITING) {