[Proposal] Detect and fail fast for dangerous to deserialize types in task activity and task orchestration. #1070
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Motivation
Regarding issue: #903 Stuck orchestrations at random on control-queue
The investigation surfaced that in task-activities via interface were calling method with cancellation token in their parameters.
Since, it becomes scheduling and running a task-activity with serialization and deserialization of parameters and return types, cancellation token was also getting deserialized.
Deserializing a cancellation token, or any object with safehandle, is dangerous as it can corrupt the native objects and result in undesirable outcomes.
E.g., for us, semaphore's locking handle got corrupt and both waitasync and release got stuck making DTF not to proceed.
Since DTF TaskOrchestration and TaskActivities do serialize and deserialize its input(parameters) and output(return type), we had fixed this in our local repo by adding guards around such task-activities and orchestration to avoid objects having safehandle as parameters or return types. Post this check, we are not hitting this issue anymore.
Since, DTF's inherent nature is such it has to serialize and deserialize input and output of task-activity and task-orchestration, it becomes important that DTF upfront understands such dangerous usage and throw to restrict bad practices.
This was the motivation behind making this change in DTF core library.
Proposal
Proposal is to add an extension to validate any type for dangerous deserialization and use it to check task-orchestration and task-activity's input and output.