Skip to content

modbus_send_rtu while(spin_lock); causing infinite loop. #932

Open

Description

@andrewmarles

I found an issue where modbus_send_rtu would get stuck on waiting for the spin lock when it was called in the context of

packet->callbacks.on_rx_exception(ModBus_CRCError, packet->msg.context);

This seemed to be related to having two sources calling modbus_send in rapid succession (Modbus RGB plugin and VFD plugin). I was able to work around it by releasing the spinlock around the callback, but I'm not sure this is the best solution:

spin_lock = false;
packet->callbacks.on_rx_exception(ModBus_CRCError, packet->msg.context);
spin_lock = true;

I have also put the same unlock around the rx_timeout callback.

Activity

  1. terjeio commented on Apr 2, 2026

    @terjeio
    Contributor

    Moving the spinlock is better? Or just removing it since queueing blocking calls is not possible?

        if((block &= !sys.blocking_event)) {
    
            if(is_blocking)
                return false;
    
            while(spin_lock);
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions