Skip to content

[P1][bug] Restore DELIMITER state machine hangs on truncated stored-program dumps #360

Closed

Description

@EVWorth

Context

Restore feature. Per docs/audits/backup.md F4.

Problem

src/lib/sql-import.ts:39-110 splitSqlStatements tracks delimiter state. If dump contains DELIMITER // followed by stored program body, then DELIMITER ; is missing (truncated file), state machine keeps custom delimiter and waits forever — no progress, no error, hang. Quoted identifier containing the word DELIMITER shifts state incorrectly.

Files

  • src/lib/sql-import.ts:39-110

Repro

  1. Create dump: DELIMITER // followed by CREATE PROCEDURE body, no terminating DELIMITER ;
  2. Attempt restore
  3. Observe hang

Expected

Clear error: "restore incomplete, last statement truncated" rather than hang.

Proposed fix

S: guard DELIMITER recognition — only match when begins at column 1 AND followed by whitespace + non-quote char. Reset delimiter to ; on any unhandled EOF.

Acceptance

Stored-program dump from mysqldump --routines restores cleanly; truncated version produces clear error rather than hanging.

Needs human verify

yes

Activity

  1. added
    audit
    severity/p1
    kind/bug
    area/backup
    on Jul 31, 2026
  2. EVWorth commented on Sep 12, 2026

    @EVWorth
    OwnerAuthor

    Fixed in #652, and the splitter moved out of the renderer entirely.

    The state machine now lives in mas-core::restore, is fed the file in chunks as it is read, and finish() reports what the file ended in the middle of:

    • a quoted string
    • a quoted identifier
    • a /* */ comment
    • a stored program whose DELIMITER was never restored — your case

    Each is an error naming the tail of the file so the user can recognise which one it is, capped so a truncated 100 MB INSERT does not quote a megabyte back at them. Previously the loop just kept accumulating and the restore made no progress and raised nothing.

    Your second observation — "a quoted identifier containing the word DELIMITER shifts state incorrectly" — was the same shape and is fixed by the same rule you proposed: DELIMITER is recognised only at the start of a statement and only when whitespace follows it, so SELECT delimiter FROM t no longer changes the terminator for the rest of the file. There is a test for it.

    A dump from mysqldump --routines restores cleanly (test: a_stored_program_restores_whole), and the truncated version reports rather than hanging (a_truncated_stored_program_reports_rather_than_hanging), which is your acceptance criterion exactly. It also reports that the statements before the truncation did apply, which is what a user needs before running the file again.

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/p1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions