cybergarage / uecho

uEcho for C is a portable and cross platform development framework for ECHONET Lite developers.
http://www.cybergarage.org/
BSD 3-Clause "New" or "Revised" License
12 stars 8 forks source link

mutex locked issue seen during network interface disconnect #1

Closed atan1 closed 6 years ago

atan1 commented 6 years ago

Hello, We ran into an issue where upon loss of network interface connection (eth0 went down), our process got stuck waiting for uecho_mutex_lock() in uecho_controller_postmessage(). From code review, we believe the issue is due to a prior call to uecho_controller_postmessage() where it failed to send a message and returned prior to unlocking the mutex. We made the fix below and it has resolved our issue. Now, when the network interface is lost, the process no longer hangs and is able to resume operation once the network interface has been restored.

In controller.c, we add the code in bold below.

/****

bool uecho_controller_postmessage(uEchoController ctrl, uEchoObject obj, uEchoMessage reqMsg, uEchoMessage resMsg) { bool isResponceReceived; int n;

if (!ctrl) return false;

uecho_mutex_lock(ctrl->mutex);

uecho_controller_setpostrequestmessage(ctrl, reqMsg); uecho_controller_setpostresponsemessage(ctrl, resMsg);

if (!uecho_controller_sendmessage(ctrl, obj, reqMsg)) { uecho_mutex_unlock(ctrl->mutex); return false; }

isResponceReceived = false; for (n=0; n<uEchoControllerPostResponseLoopCount; n++) { uecho_sleep(ctrl->postResWaitMiliTime / uEchoControllerPostResponseLoopCount); if (uecho_controller_ispostresponsereceived(ctrl)) { isResponceReceived = true; break; } }

uecho_controller_setpostrequestmessage(ctrl, NULL); uecho_controller_setpostresponsemessage(ctrl, NULL);

uecho_mutex_unlock(ctrl->mutex);

return isResponceReceived; }

cybergarage commented 6 years ago

@atan1 c I fixed the problem and release it as v0.9.2 now. Thanks for your report.

atan1 commented 6 years ago

Thanks Konno-san. Also, thank you for developing and sharing your uecho package.

On Tue, Nov 13, 2018 at 6:17 AM Satoshi Konno notifications@github.com wrote:

@atan1 https://github.com/atan1 c I fixed the problem and release it as v0.9.2 now. Thanks for your report.

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHub https://github.com/cybergarage/uecho-c/issues/1#issuecomment-438281243, or mute the thread https://github.com/notifications/unsubscribe-auth/AOg-JfE3045dlO-RpYNBzZZePfI8b3vFks5uutR2gaJpZM4YVTC1 .