[PR #13] [MERGED] fix(core): lifecycle management, bounded caches, and memory safety across 11 crates #17

Closed
opened 2026-03-02 05:12:33 +03:00 by kerem · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/gotempsh/temps/pull/13
Author: @dviejokfs
Created: 2/19/2026
Status: Merged
Merged: 2/25/2026
Merged by: @dviejokfs

Base: mainHead: feat/postgres-backup-sidecar


📝 Commits (10+)

  • 3bb96e9 feat(providers,backup,core): pg_dump sidecar backup, preset registry, and error hardening
  • 4b5616d fix(core): lifecycle management, bounded caches, and memory safety across 11 crates
  • c6dd56f fix(environments): remove useless .into() conversions on chrono::Utc::now() in tests
  • 6cad3cd fix(backup): switch pg_dump to plain format to fix OOM and add error logging
  • 92c0041 refactor(backup): update backup file extensions and improve sidecar memory management
  • 023a5eb refactor(backup): enhance backup process with direct file writing and improved error handling
  • e5b82c2 fix(backup): extend command duration for backup sidecar to prevent OOM issues
  • a15552d refactor(backup): update backup container configuration for improved access and clarity
  • 9ea5e80 refactor(backup): optimize pg_dump execution to prevent memory issues
  • 8ec782b chore: update Docker configurations and backup service enhancements

📊 Changes

79 files changed (+9783 additions, -2449 deletions)

View changed files

📝 .gitignore (+2 -0)
📝 CHANGELOG.md (+9 -0)
📝 Cargo.lock (+2 -0)
📝 Cargo.toml (+3 -0)
📝 apps/temps-cli/src/commands/errors/index.ts (+334 -3)
📝 crates/temps-analytics-events/Cargo.toml (+2 -0)
📝 crates/temps-analytics-events/src/handlers/events_handler.rs (+747 -3)
📝 crates/temps-analytics-events/src/plugin.rs (+2 -0)
📝 crates/temps-analytics-events/src/types/requests.rs (+36 -0)
📝 crates/temps-analytics-funnels/src/services/service.rs (+243 -1)
📝 crates/temps-analytics-performance/src/services/service.rs (+374 -193)
📝 crates/temps-analytics-session-replay/src/services/service.rs (+10 -10)
📝 crates/temps-audit/src/services/audit_service.rs (+2 -3)
📝 crates/temps-backup/src/handlers/backup_handler.rs (+34 -46)
📝 crates/temps-backup/src/services/backup.rs (+1772 -309)
📝 crates/temps-cli/src/commands/backup.rs (+24 -3)
📝 crates/temps-core/src/plugin.rs (+49 -53)
📝 crates/temps-core/templates.yaml (+28 -0)
📝 crates/temps-deployer/src/docker.rs (+35 -10)
📝 crates/temps-deployments/src/handlers/deployments.rs (+15 -3)

...and 59 more files

📄 Description

Summary

Comprehensive memory safety, lifecycle management, and performance improvements across 11 crates. Fixes OOM risks, resource leaks, unbounded caches, and adds proper shutdown/cleanup semantics to long-running background tasks.

Changes

Backup & Data Safety

  • pg_dump sidecar pattern — Streams backups through a sidecar container instead of loading into memory, preventing OOM on large TimescaleDB databases
  • Branch uniqueness validation — Environments now enforce unique branch names per project

Memory & Performance Fixes

  • SQL percentile_cont() — Replaces in-memory percentile sorting in analytics-performance
  • select_only() for source maps — Avoids fetching blob content when listing source maps
  • Temp file tar streaming — Docker build context uses temp files instead of in-memory buffers
  • Tail-limited build logs — Caps stored build output to prevent unbounded growth
  • Bounded session replayLIMIT + bulk UPDATE on large replay queries
  • LazyLock regexes — Error tracking regexes compiled once instead of per-request

Lifecycle & Resource Management (6 fixes)

  • DigestScheduler Arc cycle (temps-notifications) — new() returns plain Self instead of Arc<Self>, added start()/shutdown() methods + Drop for clean cancellation
  • RouteTableListener leaked spawn (temps-routes) — Stores JoinHandle in Mutex, added shutdown() + Drop. Spawned task captures only Arc<CachedPeerTable> instead of Arc<Self>
  • ProjectChangeListener no cancellation (temps-routes) — Changed start_listening from consuming self to &self, spawns internal task with stored JoinHandle + Drop
  • MetricsCache unbounded (temps-analytics-funnels) — Added max_capacity (default 1000). Evicts expired entries first, then oldest-by-expiration on overflow
  • OutageDetectionService unbounded monitor_states (temps-monitoring) — scan_monitors() now prunes entries for monitors no longer in the active DB set
  • WebhookEventListener no Drop (temps-webhooks) — Added Drop impl using try_write() to abort spawned task handle

Other Improvements

  • Source map CLI commandstemps errors sourcemaps upload/list/delete
  • Analytics events — OpenAPI spec improvements and handler refactoring
  • Deployments — Workflow execution and job processor improvements

Testing

28 new tests covering lifecycle, bounded cache, and cleanup behavior:

  • 6 tests for DigestScheduler lifecycle (64 total in crate)
  • 3 tests for RouteTableListener shutdown/Drop (42 total in crate)
  • 3 tests for ProjectChangeListener shutdown/Drop (42 total in crate)
  • 8 tests for MetricsCache bounded capacity and eviction (17 total in crate)
  • 4 tests for OutageDetectionService state pruning (21 total in crate)
  • 4 tests for WebhookEventListener Drop behavior (12 total in crate)

Crates Modified (30 files)

temps-backup, temps-deployer, temps-deployments, temps-environments, temps-error-tracking, temps-analytics-events, temps-analytics-funnels, temps-analytics-performance, temps-analytics-session-replay, temps-monitoring, temps-notifications, temps-routes, temps-webhooks, temps-projects, temps-status-page, temps-cli


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/gotempsh/temps/pull/13 **Author:** [@dviejokfs](https://github.com/dviejokfs) **Created:** 2/19/2026 **Status:** ✅ Merged **Merged:** 2/25/2026 **Merged by:** [@dviejokfs](https://github.com/dviejokfs) **Base:** `main` ← **Head:** `feat/postgres-backup-sidecar` --- ### 📝 Commits (10+) - [`3bb96e9`](https://github.com/gotempsh/temps/commit/3bb96e9ef8b849c7fe0d98f9907b8a5091117d8c) feat(providers,backup,core): pg_dump sidecar backup, preset registry, and error hardening - [`4b5616d`](https://github.com/gotempsh/temps/commit/4b5616d0753eb4761a023f41692a070d2d7a1098) fix(core): lifecycle management, bounded caches, and memory safety across 11 crates - [`c6dd56f`](https://github.com/gotempsh/temps/commit/c6dd56f29302c19e6f049ab4829598b43efcb3b6) fix(environments): remove useless .into() conversions on chrono::Utc::now() in tests - [`6cad3cd`](https://github.com/gotempsh/temps/commit/6cad3cd1f83dfefac3c72f40c2008f16693b82fc) fix(backup): switch pg_dump to plain format to fix OOM and add error logging - [`92c0041`](https://github.com/gotempsh/temps/commit/92c0041046349efc0b40208956ea4fc114661f58) refactor(backup): update backup file extensions and improve sidecar memory management - [`023a5eb`](https://github.com/gotempsh/temps/commit/023a5eb6c3936959209c78adfb25b630d24eb31a) refactor(backup): enhance backup process with direct file writing and improved error handling - [`e5b82c2`](https://github.com/gotempsh/temps/commit/e5b82c2a8dd2d3f0ed0ee4b784279236f62635be) fix(backup): extend command duration for backup sidecar to prevent OOM issues - [`a15552d`](https://github.com/gotempsh/temps/commit/a15552d32ba47b57175cfc542ddbb847d8ce2bc6) refactor(backup): update backup container configuration for improved access and clarity - [`9ea5e80`](https://github.com/gotempsh/temps/commit/9ea5e808a6fcb970512de37f22f69d1e5ee57bf4) refactor(backup): optimize pg_dump execution to prevent memory issues - [`8ec782b`](https://github.com/gotempsh/temps/commit/8ec782b4619334ad8b05465cec0c8839cdac6f3f) chore: update Docker configurations and backup service enhancements ### 📊 Changes **79 files changed** (+9783 additions, -2449 deletions) <details> <summary>View changed files</summary> 📝 `.gitignore` (+2 -0) 📝 `CHANGELOG.md` (+9 -0) 📝 `Cargo.lock` (+2 -0) 📝 `Cargo.toml` (+3 -0) 📝 `apps/temps-cli/src/commands/errors/index.ts` (+334 -3) 📝 `crates/temps-analytics-events/Cargo.toml` (+2 -0) 📝 `crates/temps-analytics-events/src/handlers/events_handler.rs` (+747 -3) 📝 `crates/temps-analytics-events/src/plugin.rs` (+2 -0) 📝 `crates/temps-analytics-events/src/types/requests.rs` (+36 -0) 📝 `crates/temps-analytics-funnels/src/services/service.rs` (+243 -1) 📝 `crates/temps-analytics-performance/src/services/service.rs` (+374 -193) 📝 `crates/temps-analytics-session-replay/src/services/service.rs` (+10 -10) 📝 `crates/temps-audit/src/services/audit_service.rs` (+2 -3) 📝 `crates/temps-backup/src/handlers/backup_handler.rs` (+34 -46) 📝 `crates/temps-backup/src/services/backup.rs` (+1772 -309) 📝 `crates/temps-cli/src/commands/backup.rs` (+24 -3) 📝 `crates/temps-core/src/plugin.rs` (+49 -53) 📝 `crates/temps-core/templates.yaml` (+28 -0) 📝 `crates/temps-deployer/src/docker.rs` (+35 -10) 📝 `crates/temps-deployments/src/handlers/deployments.rs` (+15 -3) _...and 59 more files_ </details> ### 📄 Description ## Summary Comprehensive memory safety, lifecycle management, and performance improvements across 11 crates. Fixes OOM risks, resource leaks, unbounded caches, and adds proper shutdown/cleanup semantics to long-running background tasks. ## Changes ### Backup & Data Safety - **pg_dump sidecar pattern** — Streams backups through a sidecar container instead of loading into memory, preventing OOM on large TimescaleDB databases - **Branch uniqueness validation** — Environments now enforce unique branch names per project ### Memory & Performance Fixes - **SQL `percentile_cont()`** — Replaces in-memory percentile sorting in analytics-performance - **`select_only()` for source maps** — Avoids fetching blob content when listing source maps - **Temp file tar streaming** — Docker build context uses temp files instead of in-memory buffers - **Tail-limited build logs** — Caps stored build output to prevent unbounded growth - **Bounded session replay** — `LIMIT` + bulk `UPDATE` on large replay queries - **`LazyLock` regexes** — Error tracking regexes compiled once instead of per-request ### Lifecycle & Resource Management (6 fixes) - **DigestScheduler Arc cycle** (`temps-notifications`) — `new()` returns plain `Self` instead of `Arc<Self>`, added `start()`/`shutdown()` methods + `Drop` for clean cancellation - **RouteTableListener leaked spawn** (`temps-routes`) — Stores `JoinHandle` in `Mutex`, added `shutdown()` + `Drop`. Spawned task captures only `Arc<CachedPeerTable>` instead of `Arc<Self>` - **ProjectChangeListener no cancellation** (`temps-routes`) — Changed `start_listening` from consuming `self` to `&self`, spawns internal task with stored `JoinHandle` + `Drop` - **MetricsCache unbounded** (`temps-analytics-funnels`) — Added `max_capacity` (default 1000). Evicts expired entries first, then oldest-by-expiration on overflow - **OutageDetectionService unbounded monitor_states** (`temps-monitoring`) — `scan_monitors()` now prunes entries for monitors no longer in the active DB set - **WebhookEventListener no Drop** (`temps-webhooks`) — Added `Drop` impl using `try_write()` to abort spawned task handle ### Other Improvements - **Source map CLI commands** — `temps errors sourcemaps upload/list/delete` - **Analytics events** — OpenAPI spec improvements and handler refactoring - **Deployments** — Workflow execution and job processor improvements ## Testing 28 new tests covering lifecycle, bounded cache, and cleanup behavior: - 6 tests for DigestScheduler lifecycle (64 total in crate) - 3 tests for RouteTableListener shutdown/Drop (42 total in crate) - 3 tests for ProjectChangeListener shutdown/Drop (42 total in crate) - 8 tests for MetricsCache bounded capacity and eviction (17 total in crate) - 4 tests for OutageDetectionService state pruning (21 total in crate) - 4 tests for WebhookEventListener Drop behavior (12 total in crate) ## Crates Modified (30 files) `temps-backup`, `temps-deployer`, `temps-deployments`, `temps-environments`, `temps-error-tracking`, `temps-analytics-events`, `temps-analytics-funnels`, `temps-analytics-performance`, `temps-analytics-session-replay`, `temps-monitoring`, `temps-notifications`, `temps-routes`, `temps-webhooks`, `temps-projects`, `temps-status-page`, `temps-cli` --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
kerem 2026-03-02 05:12:33 +03:00
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
starred/temps#17
No description provided.