Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove redundant and error-prone call to .Reset() in our AutoResetEvents #68

Merged
merged 7 commits into from
Sep 11, 2023

Conversation

davidmrdavid
Copy link
Collaborator

@davidmrdavid davidmrdavid commented Sep 5, 2023

The standalone DF PS SDK manages two threads: (1) the user-code thread and (2) the DTFx thread. Only one thread can be active at a time, and yield control to any given thread using AutoReset events.

In today's implementation, in order to yield control to the other thread, we perform the following steps, in order:
(A) We wake the other thread
(B) We manually reset this thread's AutoReset event (there's technically no reason to do this, the autoresetevent should automatically reset after its corresponding thread wakes up)
(C) We block this thread until the AutoReset event is signaled.

After step (A) but before step (B), it's possible for the complement thread to signal the yielding thread's autoreset event. If this occurs, then in step (B) we will discard the complement thread's signal because we reset the AutoReset event. At that point, the orchestrator gets stuck.

In this PR, we remove the redundant call to the .Reset() API to avoid this race condition. Now we rely solely on the automatic reset of this data structure.

This should fix: #65

@davidmrdavid davidmrdavid changed the title Ensure active thread's AutoReset event is reset before yielding to completement thread Remove redundant and error-prone call to .Reset() in our AutoResetEvents Sep 5, 2023
michaelpeng36
michaelpeng36 previously approved these changes Sep 7, 2023
@davidmrdavid
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidmrdavid
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidmrdavid
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidmrdavid
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidmrdavid
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidmrdavid
Copy link
Collaborator Author

/azp run

@azure-pipelines
Copy link

Azure Pipelines successfully started running 1 pipeline(s).

@davidmrdavid davidmrdavid merged commit 090cdcf into main Sep 11, 2023
1 check passed
@davidmrdavid davidmrdavid deleted the dajusto/patch-thread-yielding branch September 11, 2023 16:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Durable activity failures still not working properly in Fan out/Fan in orchestrator
2 participants