forge
Explore
Log in

Don't you dare go Hollow

A job stopped under memory pressure has its workspace removed before it goes back to the queue, so a free slot on the same runner that claims it again no longer has its folder deleted under it (git init: cannot change to the work folder)

Browse files at this commit

529f562306c8fc734fc3bcdc94986bd6a773bc7cAhmet Kaan GümüşParent: 20f68ae
Some checks failed
Show checks
  • ✗ci/buildjob was cancelledDetails
  • fix
    • a job stopped under memory pressure has its workspace removed before it goes back to the queue, so a free slot on the same runner that claims it again no longer has its folder deleted under it (git init: cannot change to the work folder)
    • a forge restart or self-update no longer fails running jobs: after boot nothing is reaped for two minutes, so runners report in first, and a runner keeps offering a finished job's result for up to ten minutes while the forge cannot be reached, giving up early only when the forge refuses it 📝 docs: CI says what a forge restart does to running jobs
Show full message
🐛 fix: a job stopped under memory pressure has its workspace removed before it goes back to the queue, so a free slot on the same runner that claims it again no longer has its folder deleted under it (git init: cannot change to the work folder); a forge restart or self-update no longer fails running jobs: after boot nothing is reaped for two minutes, so runners report in first, and a runner keeps offering a finished job's result for up to ten minutes while the forge cannot be reached, giving up early only when the forge refuses it 📝 docs: CI says what a forge restart does to running jobs
crates/forge-runner/src/runner.rsmodified+25 -8
@@ -31,7 +31,8 @@ use crate::workspace;
3131 /// Log lines queued between the executor and the log shipper.
3232 const LOG_CHANNEL: usize = 64;
3333 /// How many times the runner tries to report a finished job.
34-const FINISH_ATTEMPTS: u32 = 5;
34+/// How long a result is retried while the forge cannot be reached (a restart or a self-update).
35+const FINISH_PATIENCE: Duration = Duration::from_secs(10 * 60);
3536 /// Largest single artifact the runner will upload. The forge enforces its own total cap.
3637 const MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024;
3738 /// How long a stopping runner waits for its last log lines to reach the forge.
@@ -479,6 +480,13 @@ impl Runner {
479480 drop(registration);
480481 drop(tx);
481482 let _ = pump.await;
483+ // The workspace is named after the job, so it goes before the job is handed back: a
484+ // free slot here may claim it again at once and build in the same folder.
485+ if let Some(dir) = workspace_dir.take()
486+ && let Err(e) = workspace::cleanup(&dir).await
487+ {
488+ tracing::warn!(job_id = %job.job_id, error = %e, "workspace cleanup failed");
489+ }
482490 let reason = "killed under memory pressure on the runner";
483491 if let Err(e) = self
484492 .client
@@ -495,11 +503,6 @@ impl Runner {
495503 };
496504 self.finish(&job, &failed, None).await;
497505 }
498- if let Some(dir) = workspace_dir
499- && let Err(e) = workspace::cleanup(&dir).await
500- {
501- tracing::warn!(job_id = %job.job_id, error = %e, "workspace cleanup failed");
502- }
503506 tracing::info!(job_id = %job.job_id, "job requeued after memory pressure");
504507 return Outcome::Cancelled;
505508 }
@@ -632,12 +635,26 @@ impl Runner {
632635 oom_killed: oom_kills.map(|_| true),
633636 oom_kills,
634637 };
635- for attempt in 1..=FINISH_ATTEMPTS {
638+ // A forge that is down or restarting is waited for; a forge that refuses the result
639+ // (the job was reaped, cancelled or its token ended) is not asked again.
640+ let started = Instant::now();
641+ let mut attempt = 0u32;
642+ loop {
643+ attempt += 1;
636644 match self.client.finish(&job.job_id, &job.job_token, &req).await {
637645 Ok(()) => return,
638646 Err(e) => {
639647 tracing::warn!(job_id = %job.job_id, attempt, error = %e, "finish failed");
640- tokio::time::sleep(Duration::from_secs(2 * u64::from(attempt))).await;
648+ let away = match &e {
649+ ClientError::Http(_) => true,
650+ ClientError::Status { status, .. } => status.is_server_error(),
651+ _ => false,
652+ };
653+ if (!away && attempt >= 3) || started.elapsed() >= FINISH_PATIENCE {
654+ break;
655+ }
656+ let wait = Duration::from_secs((2 * u64::from(attempt)).min(15));
657+ tokio::time::sleep(wait).await;
641658 }
642659 }
643660 }
crates/forge-web/src/ci/reaper.rsmodified+7 -1
@@ -37,9 +37,15 @@ async fn run(state: AppState) {
3737 let mut next_purge = Instant::now();
3838 let mut next_slow_alerts = Instant::now() + ALERTS_SLOW_EVERY;
3939 let mut next_health = Instant::now() + HEALTH_EVERY;
40+ // After a restart or a self-update, every running job's last heartbeat is as old as the
41+ // downtime. Its runner kept working and beats again within seconds, so nothing is reaped
42+ // until a full LOST_AFTER has passed since boot.
43+ let booted = Instant::now();
4044 loop {
4145 tick.tick().await;
42- reap_once(&state).await;
46+ if booted.elapsed() >= LOST_AFTER {
47+ reap_once(&state).await;
48+ }
4349 crate::alerts::check_runners(&state).await;
4450 if Instant::now() >= next_health {
4551 crate::live::admin().bump(&crate::live::Topic::AdminHealth);
docs/ci.mdmodified+5 -0
@@ -622,6 +622,11 @@ jobs are running, the runner stops claiming, replaces its binary, and exits with
622622 restarts it. It is skipped when the forge's binary is for a different OS or architecture. Set
623623 `auto_update = false` to pin the binary by hand.
624624
625+A forge restart or self-update does not stop running jobs: they keep running on their runners, which
626+keep their logs and retry heartbeats until the forge answers again. A job that finishes while the
627+forge is away keeps offering its result for up to 10 minutes. After it boots, the forge waits two
628+minutes before it marks any job lost, so runners have time to report in.
629+
625630 `concurrency` is the number of jobs run in parallel. The default is 1. An admin can change it per runner
626631 on the runners page (`/admin/runners`) with no restart: type a number from 1 to 64 and save. The
627632 runner picks it up on its next claim or job heartbeat, grows or shrinks its job slots, and logs