From 68ac771785aac083ecd17937f6f540620442492f Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Thu, 3 Dec 2026 23:14:59 +1100 Subject: [PATCH 1/2] linuxcncrsh: wait for task to receive SET ESTOP and SET MACHINE tests/t0/nonrandom failed once on an arm CI runner with every MDI line refused: "Machine must be 'ON' for SET MDI". SET ESTOP and SET MACHINE send the state command and then watch the motion heartbeat in task's status for the new state, giving up after one second without a heartbeat. On a state change the interpreter writes the parameter file and calls fdatasync(). On a slow disk that call can take seconds, and task publishes no status meanwhile, so the heartbeat stands still. linuxcncrsh then reported a failure for a command that task was still working on, went on to the next one, and the machine never came on. Wait for task to echo the command before watching the heartbeat. Tested by delaying that fdatasync() by 3.45 s with a preload shim: t0/nonrandom fails the same way as on CI without the change and passes with it. --- src/emc/usr_intf/emcrsh.cc | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/src/emc/usr_intf/emcrsh.cc b/src/emc/usr_intf/emcrsh.cc index 409c267f0b5..77b56c45812 100644 --- a/src/emc/usr_intf/emcrsh.cc +++ b/src/emc/usr_intf/emcrsh.cc @@ -1009,6 +1009,13 @@ static cmdResponseType setMachine(connectionRecType &ctx) return rtError; break; } + // Task may be busy for a while before it gets to the command (the + // interpreter syncs the parameter file to disk on a state change) and + // its status, heartbeat included, stands still until then. + if (emcCommandWaitReceived()) { + errornl(ctx, fmt::format("Waiting for task to receive 'SET MACHINE {}' failed", onOff(machon))); + return rtError; + } // Setting machine on/off takes a moment // We need to wait for the motion controller to catch up // and set/clear the motion enable flag internally. @@ -1052,6 +1059,11 @@ static cmdResponseType setEStop(connectionRecType &ctx) break; } + // Task's status stands still until it has handled the command, see setMachine() + if (emcCommandWaitReceived()) { + errornl(ctx, fmt::format("Waiting for task to receive 'SET ESTOP {}' failed", onOff(estopon))); + return rtError; + } // Setting/clearing ESTOP takes a moment for(unsigned toc = 0; toc < WAIT_TASK_STATE_CHANGE_MAX; toc++) { // Wait for the motion control to run From f7a5cd953a4af42c8c6ea0e04ab9a3ba1ab3e02c Mon Sep 17 00:00:00 2001 From: Luca Toniolo <10792599+grandixximo@users.noreply.github.com> Date: Fri, 4 Dec 2026 00:25:04 +1100 Subject: [PATCH 2/2] linuxcncrsh: bound the wait for task to receive a command emcTimeout is 0 in linuxcncrsh, so the wait added for SET ESTOP and SET MACHINE blocked every client for as long as task did not answer. Move it to a helper that waits at most 10 s, and use it in SET JOINT_HOME too, which watches the heartbeat the same way. --- src/emc/usr_intf/emcrsh.cc | 34 ++++++++++++++++++++++++---------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/src/emc/usr_intf/emcrsh.cc b/src/emc/usr_intf/emcrsh.cc index 77b56c45812..a21b3bc26e5 100644 --- a/src/emc/usr_intf/emcrsh.cc +++ b/src/emc/usr_intf/emcrsh.cc @@ -68,6 +68,9 @@ constexpr auto JOINT_WAIT_HOMED_SLEEP = 100ms; // Sleep time between checks // up and reflect a requested state change in the status #define WAIT_TASK_STATE_CHANGE_MAX 25 +// Maximum wait time for task to receive a command +#define WAIT_TASK_RECEIVED_TIMEOUT 10.0 + typedef enum { cmdUnknown, cmdHello, cmdSet, cmdGet, cmdQuit, cmdShutdown, cmdHelp } cmdType; typedef enum { @@ -908,6 +911,23 @@ static cmdResponseType doWaitHeartbeat(connectionRecType &ctx, int periods, doub return rtError; } +// Task may be busy for a while before it gets to a command (the interpreter +// syncs the parameter file to disk on a state change) and its status, +// heartbeat included, stands still until then. emcTimeout is 0 (infinite) +// in linuxcncrsh, so bound the wait. +static cmdResponseType waitTaskReceived(connectionRecType &ctx, const std::string &cmd) +{ + double saved = emcTimeout; + emcTimeout = WAIT_TASK_RECEIVED_TIMEOUT; + int rv = emcCommandWaitReceived(); + emcTimeout = saved; + if (rv) { + errornl(ctx, fmt::format("Task did not receive '{}' within {:.1f} seconds", cmd, WAIT_TASK_RECEIVED_TIMEOUT)); + return rtError; + } + return rtOk; +} + static cmdResponseType setJointWaitHomed(connectionRecType &ctx) { // SET JOINT_WAIT_HOMED [joint] [timeout] @@ -1009,13 +1029,8 @@ static cmdResponseType setMachine(connectionRecType &ctx) return rtError; break; } - // Task may be busy for a while before it gets to the command (the - // interpreter syncs the parameter file to disk on a state change) and - // its status, heartbeat included, stands still until then. - if (emcCommandWaitReceived()) { - errornl(ctx, fmt::format("Waiting for task to receive 'SET MACHINE {}' failed", onOff(machon))); + if (rtOk != waitTaskReceived(ctx, fmt::format("SET MACHINE {}", onOff(machon)))) return rtError; - } // Setting machine on/off takes a moment // We need to wait for the motion controller to catch up // and set/clear the motion enable flag internally. @@ -1059,11 +1074,8 @@ static cmdResponseType setEStop(connectionRecType &ctx) break; } - // Task's status stands still until it has handled the command, see setMachine() - if (emcCommandWaitReceived()) { - errornl(ctx, fmt::format("Waiting for task to receive 'SET ESTOP {}' failed", onOff(estopon))); + if (rtOk != waitTaskReceived(ctx, fmt::format("SET ESTOP {}", onOff(estopon)))) return rtError; - } // Setting/clearing ESTOP takes a moment for(unsigned toc = 0; toc < WAIT_TASK_STATE_CHANGE_MAX; toc++) { // Wait for the motion control to run @@ -1457,6 +1469,8 @@ static cmdResponseType setJointHome(connectionRecType &ctx) return rtError; if (joint >= 0) { + if (rtOk != waitTaskReceived(ctx, fmt::format("SET JOINT_HOME {}", joint))) + return rtError; // The motion controller needs a servo-thread run to raise the // homing flag. Wait for it so that a following command, like // 'SET JOINT_WAIT_HOMED', can rely on the state being visible.