aboutsummaryrefslogtreecommitdiffstats
path: root/models/actions
diff options
context:
space:
mode:
authorJason Song <i@wolfogre.com>2023-06-29 01:07:29 +0800
committerGitHub <noreply@github.com>2023-06-28 19:07:29 +0200
commit6daf21c9b722e31ea5e3b1ec48caa69327580abd (patch)
treed689df26a38ed3a6124d475613c4f899127aa7bf /models/actions
parentb6693a2c9a6010463950bbd89a2bfee88bde5e5f (diff)
downloadgitea-6daf21c9b722e31ea5e3b1ec48caa69327580abd.tar.gz
gitea-6daf21c9b722e31ea5e3b1ec48caa69327580abd.zip
Fix content holes in Actions task logs file (#25560)
Fix #25451. Bugfixes: - When stopping the zombie or endless tasks, set `LogInStorage` to true after transferring the file to storage. It was missing, it could write to a nonexistent file in DBFS because `LogInStorage` was false. - Always update `ActionTask.Updated` when there's a new state reported by the runner, even if there's no change. This is to avoid the task being judged as a zombie task. Enhancement: - Support `Stat()` for DBFS file. - `WriteLogs` refuses to write if it could result in content holes. --------- Co-authored-by: Giteabot <teabot@gitea.io>
Diffstat (limited to 'models/actions')
-rw-r--r--models/actions/task.go9
1 files changed, 9 insertions, 0 deletions
diff --git a/models/actions/task.go b/models/actions/task.go
index 79b1d46dd0..719fd19365 100644
--- a/models/actions/task.go
+++ b/models/actions/task.go
@@ -344,6 +344,9 @@ func UpdateTask(ctx context.Context, task *ActionTask, cols ...string) error {
return err
}
+// UpdateTaskByState updates the task by the state.
+// It will always update the task if the state is not final, even there is no change.
+// So it will update ActionTask.Updated to avoid the task being judged as a zombie task.
func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionTask, error) {
stepStates := map[int64]*runnerv1.StepState{}
for _, v := range state.Steps {
@@ -384,6 +387,12 @@ func UpdateTaskByState(ctx context.Context, state *runnerv1.TaskState) (*ActionT
}, nil); err != nil {
return nil, err
}
+ } else {
+ // Force update ActionTask.Updated to avoid the task being judged as a zombie task
+ task.Updated = timeutil.TimeStampNow()
+ if err := UpdateTask(ctx, task, "updated"); err != nil {
+ return nil, err
+ }
}
if err := task.LoadAttributes(ctx); err != nil {