fix: fixed a race condition for terraform task statuses#3686
Merged
fiftin merged 1 commit intosemaphoreui:developfrom Mar 9, 2026
Merged
fix: fixed a race condition for terraform task statuses#3686fiftin merged 1 commit intosemaphoreui:developfrom
fiftin merged 1 commit intosemaphoreui:developfrom
Conversation
…onfirmation and confirmed for runners
Collaborator
|
Hi @JulianKap thank you! Have you test it? |
Contributor
Author
|
Hi @fiftin ! Yes, I tested this fix on individual runners, and the error in the terraform template did not reproduce (I also tested Ansible templates). I also added temporary logs to track the behavior when receiving server statuses, which confirmed that the issue had been fixed. |
Collaborator
|
Thank you! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
PR Title
Fix race condition in runner task status sync causing incorrect confirmation state for Terraform tasks
Description
This PR fixes a race condition in the runner that could overwrite task confirmation statuses during synchronization with the server.
Observed problem
When using separate runners and executing Terraform tasks, there were situations where the task should transition to the "waiting for confirmation" state after
terraform plandetects infrastructure changes.However, the task remained in the "running" state even though the logs clearly showed that Terraform had finished the plan phase and was waiting for confirmation.
As a result:
This behavior was intermittent and difficult to reproduce reliably.
Root cause
The runner uses two concurrent goroutines:
A race condition could occur in the following scenario:
running).As a result, instead of sending the expected "waiting for confirmation" status, the runner sends "running", effectively losing the confirmation state.
Additional issue
A similar race condition also affected the "confirmed" status.
In this case the issue was mostly visual and did not affect actual task execution, but the root cause was the same concurrent state overwrite.
Solution
The fix ensures that task status updates from the server do not overwrite local runner states that have already transitioned to confirmation-related statuses.
This prevents the runner from reverting task states when synchronization happens concurrently with local state transitions.
Result