espressif / esp-modbus

ESP-Modbus - the officially suppported library for Modbus protocol (serial RS485 + TCP over WiFi or Ethernet).
Apache License 2.0
100 stars 48 forks source link

vMBMasterRunResRelease(231): Resource release failure (IDFGH-7906) #10

Closed ph2355 closed 10 months ago

ph2355 commented 2 years ago

Hi, I'm constantly getting a vMBMasterRunResRelease(231): Resource release failure error in the log. In my application I use polling for about 30 modbus registers every 5 seconds through modbus RTU. The longer the app runs the more resource release failures I get through time.

So I did some digging where the error originates and got to vMBMasterRunResRelease function inside portevent_m.c file. As I understand, xMBMasterRunResTake is called before any modbus operation, and vMBMasterRunResRelease is called after. In vMBMasterRunResRelease function xEventGroupSetBits is called to set event bit, and then immediately check if the bit is set after xEventGroupSetBits returns. If the bit is not set, the function reports a resource release failure.

The problem here is that xEventGroupSetBits may not always return set bits even if the function has successfully set the desired bits. If another task is already waiting for these event bits, xEventGroupSetBits will set those bits, then check for any waiting tasks, unblock these tasks and clear the bits. xEventGroupSetBits will in this case return cleared bits, so the error check in vMBMasterRunResRelease will fail even though the bits were successfully set.

I think this line does not work as intended and is pollutting my logs. MB_PORT_CHECK((uxBits == MB_EVENT_RESOURCE), ; , "Resource release failure.");

alisitsyn commented 2 years ago

Hi @ph2355 ,

This is known thing that has been originally commented and fixed in preliminary WIP version of modbus_support repo. It does not cause any critical issue but agree should not be an error.

/**
 * This function is release Modbus Master running resource.
 * Note:The resource is define by Operating System.If you not use OS this function can be empty.
 */
void vMBMasterRunResRelease( void )
{
    EventBits_t uxBits = xEventGroupSetBits( xResourceMasterHdl, MB_EVENT_RESOURCE );
    if (uxBits != MB_EVENT_RESOURCE) {
        // The returned resource mask may be = 0, if the task waiting for it is unblocked.
        // This is not an error but expected behavior.
        ESP_LOGD(MB_PORT_TAG,"%s: Release resource (%x) fail.", __func__, uxBits);
    }
}
ph2355 commented 2 years ago

Thanks for the acknowledgement. Can I expect this to be fixed in a future version?

alisitsyn commented 2 years ago

@ph2355 ,

Yes, sure this will be fixed and I will let you know once it merged. Thank you for the contribution.

brainstorm commented 1 year ago

I second @ph2355 it's also cluttering my logs as I'm trying to debug fix issue #3, including those on ESP Insights too:

Screen Shot 2022-10-24 at 4 43 44 pm

... can you merge it in @alisitsyn?

alisitsyn commented 1 year ago

@brainstorm, @ph2355 ,

The fix is merged in commit

alisitsyn commented 10 months ago

Close the issue as fixed.