Skip to content

InvalidCastException when sending multiple RTW-Pull for the same process in short succession #719

@1nf0rmagician

Description

@1nf0rmagician

Describe the bug
When sending multiple RTW-Pull with the same process ID from a resource, an Activity is dispatched several times. This behaviour of the Process Engine is intended (while in most cases the cell's behaviour is probably not). If these request from the cell come in short succession and overlap with activity results send for this activity, it can happen that the threads for handling the activity result and for sending a new activity start create race conditions. Specifically, when the session for the activity is first set to ActivityCompleted but before the processing of the completion is finished the other thread sets it to ActivityStart again.

Following logs indicate the issue

2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Received ReadyToWork from cell 3-Repair Station. Type: Pull - Classification: Production - Process: ProcessId: 3948546  
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Received ReadyToWork from cell 3-Repair Station. Type: Pull - Classification: Production - Process: ProcessId: 3948546  
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Dispatching activity 'ProcessFixupActivity - Process = 3948546' to resource '3'  
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Dispatching activity 'ProcessFixupActivity - Process = 3948546' to resource '3'  
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Received ReadyToWork from cell 3-Repair Station. Type: Pull - Classification: Production - Process: ProcessId: 3948546  
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Received result '0' for activity 'ProcessFixupActivity - Process = 3948546' result=0, activity=ProcessFixupActivity - Process = 3948546 
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Received result '0' for activity 'ProcessFixupActivity - Process = 3948546' result=0, activity=ProcessFixupActivity - Process = 3948546 
2025-10-18 15:53:57.6064 - Debug [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Dispatching activity 'ProcessFixupActivity - Process = 3948546' to resource '3'  
2025-10-18 15:53:57.6064 - Warn [Moryx.ControlSystem.ProcessEngine.ActivityPool] - States can only increase! Current state: ResultReceived - New State: ResultReceived  
2025-10-18 15:53:57.6064 - Warn [Moryx.ControlSystem.ProcessEngine.ActivityDispatcher] - Dismissing received result 0 for currently completing activity ProcessFixupActivity - Process = 3948546 with result 0. result=0, activity=ProcessFixupActivity - Process = 3948546, previousResult=0 

We see that the state machine of the activity is resilient against the behaviour of the cell, however this line

CompleteProcessOnCell(processData, (ICompletableSession)activityData.Session, activityData.Resource);

throws an System.InvalidCastException: 'Unable to cast object of type 'Moryx.ControlSystem.Cells.ActivityStart' to type 'Moryx.ControlSystem.Cells.ICompletableSession'.', because we do not check the for the advancement in the activities state in this line

activityData.Session = activityStart;

To Reproduce
Steps to reproduce the behavior:

  1. Run the MORYX-Demo, start an order and interrupt it again
  2. Abort the running production job

Expected behavior
The job with all its activities and process is aborted.

Environment:

  • Hardware: PC
  • OS: Win10
  • Version 10.0.0-future...

Metadata

Metadata

Assignees

Labels

bugSomething isn't working

Type

Projects

No projects

Relationships

None yet

Development

No branches or pull requests

Issue actions