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 commit529f562306c8fc734fc3bcdc94986bd6a773bc7cParent: 20f68aeSome 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
3 changed files +37 -9
- crates/forge-runner/src/runner.rs +25 -8
- crates/forge-web/src/ci/reaper.rs +7 -1
- docs/ci.md +5 -0
crates/forge-runner/src/runner.rsmodified+25 -8
| @@ -31,7 +31,8 @@ use crate::workspace; | |||
| 31 | /// Log lines queued between the executor and the log shipper. | 31 | /// Log lines queued between the executor and the log shipper. |
| 32 | const LOG_CHANNEL: usize = 64; | 32 | const LOG_CHANNEL: usize = 64; |
| 33 | /// How many times the runner tries to report a finished job. | 33 | /// 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); | ||
| 35 | /// Largest single artifact the runner will upload. The forge enforces its own total cap. | 36 | /// Largest single artifact the runner will upload. The forge enforces its own total cap. |
| 36 | const MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024; | 37 | const MAX_ARTIFACT_BYTES: u64 = 512 * 1024 * 1024; |
| 37 | /// How long a stopping runner waits for its last log lines to reach the forge. | 38 | /// How long a stopping runner waits for its last log lines to reach the forge. |
| @@ -479,6 +480,13 @@ impl Runner { | |||
| 479 | drop(registration); | 480 | drop(registration); |
| 480 | drop(tx); | 481 | drop(tx); |
| 481 | let _ = pump.await; | 482 | 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 | + } | ||
| 482 | let reason = "killed under memory pressure on the runner"; | 490 | let reason = "killed under memory pressure on the runner"; |
| 483 | if let Err(e) = self | 491 | if let Err(e) = self |
| 484 | .client | 492 | .client |
| @@ -495,11 +503,6 @@ impl Runner { | |||
| 495 | }; | 503 | }; |
| 496 | self.finish(&job, &failed, None).await; | 504 | self.finish(&job, &failed, None).await; |
| 497 | } | 505 | } |
| 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 | - } | ||
| 503 | tracing::info!(job_id = %job.job_id, "job requeued after memory pressure"); | 506 | tracing::info!(job_id = %job.job_id, "job requeued after memory pressure"); |
| 504 | return Outcome::Cancelled; | 507 | return Outcome::Cancelled; |
| 505 | } | 508 | } |
| @@ -632,12 +635,26 @@ impl Runner { | |||
| 632 | oom_killed: oom_kills.map(|_| true), | 635 | oom_killed: oom_kills.map(|_| true), |
| 633 | oom_kills, | 636 | oom_kills, |
| 634 | }; | 637 | }; |
| 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; | ||
| 636 | match self.client.finish(&job.job_id, &job.job_token, &req).await { | 644 | match self.client.finish(&job.job_id, &job.job_token, &req).await { |
| 637 | Ok(()) => return, | 645 | Ok(()) => return, |
| 638 | Err(e) => { | 646 | Err(e) => { |
| 639 | tracing::warn!(job_id = %job.job_id, attempt, error = %e, "finish failed"); | 647 | 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; | ||
| 641 | } | 658 | } |
| 642 | } | 659 | } |
| 643 | } | 660 | } |
crates/forge-web/src/ci/reaper.rsmodified+7 -1
| @@ -37,9 +37,15 @@ async fn run(state: AppState) { | |||
| 37 | let mut next_purge = Instant::now(); | 37 | let mut next_purge = Instant::now(); |
| 38 | let mut next_slow_alerts = Instant::now() + ALERTS_SLOW_EVERY; | 38 | let mut next_slow_alerts = Instant::now() + ALERTS_SLOW_EVERY; |
| 39 | let mut next_health = Instant::now() + HEALTH_EVERY; | 39 | 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(); | ||
| 40 | loop { | 44 | loop { |
| 41 | tick.tick().await; | 45 | tick.tick().await; |
| 42 | - reap_once(&state).await; | 46 | + if booted.elapsed() >= LOST_AFTER { |
| 47 | + reap_once(&state).await; | ||
| 48 | + } | ||
| 43 | crate::alerts::check_runners(&state).await; | 49 | crate::alerts::check_runners(&state).await; |
| 44 | if Instant::now() >= next_health { | 50 | if Instant::now() >= next_health { |
| 45 | crate::live::admin().bump(&crate::live::Topic::AdminHealth); | 51 | 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 | |||
| 622 | restarts it. It is skipped when the forge's binary is for a different OS or architecture. Set | 622 | restarts it. It is skipped when the forge's binary is for a different OS or architecture. Set |
| 623 | `auto_update = false` to pin the binary by hand. | 623 | `auto_update = false` to pin the binary by hand. |
| 624 | 624 | ||
| 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 | + | ||
| 625 | `concurrency` is the number of jobs run in parallel. The default is 1. An admin can change it per runner | 630 | `concurrency` is the number of jobs run in parallel. The default is 1. An admin can change it per runner |
| 626 | on the runners page (`/admin/runners`) with no restart: type a number from 1 to 64 and save. The | 631 | on the runners page (`/admin/runners`) with no restart: type a number from 1 to 64 and save. The |
| 627 | runner picks it up on its next claim or job heartbeat, grows or shrinks its job slots, and logs | 632 | runner picks it up on its next claim or job heartbeat, grows or shrinks its job slots, and logs |