Skip to content

[P0][bug] generateBackup buffers entire dump in single string; large DBs OOM renderer #358

Closed

Description

@EVWorth

Context

Backup/restore feature — generateBackup is the core function. Per docs/audits/backup.md F2.

Problem

src/lib/backup-generator.ts:62-79 returns Promise and accumulates every table's CREATE + every row's INSERT into a single parts: string[] array. Renderer writes this string in one IPC call via api.writeFileContents. For a 10M-row table this is ~1-3 GB of RAM held by the WebView before the save dialog opens. No streaming, no chunked file writes, no temp file with progressive append.

Files

  • src/lib/backup-generator.ts:62-79
  • src/components/backup/BackupDialog.tsx (IPC write call site)

Repro

  1. Backup a 10M-row table (any DB)
  2. Observe WebView RSS climb to multiple GB during dump
  3. Click Cancel — already-allocated parts array cannot be reclaimed

Expected

Streaming dump that writes directly to disk in batches. Renderer RSS stays bounded.

Proposed fix

L: replace generateBackup(...) -> Promise with #[tauri::command] backup_database_stream(connection_id, database, options, output_path) -> Result<u64, String> that opens file with tokio::fs::File, iterates tables, runs SELECT in 10k-row batches, writes INSERT batches directly to disk. Update BackupDialog to call new command.

Acceptance

Backup of synthetic 5 GB table completes with renderer RSS < 200 MB; output byte-equivalent to current in-memory dump; existing tests pass.

Needs human verify

yes (memory profile needs profiling)

Activity

  1. added
    audit
    severity/p0
    kind/bug
    area/backup
    on Jul 31, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    area/backupauditkind/bugseverity/p0

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions