Skip to content

cli: an interrupt can leave the temporary file -o writes, and the CLI never cancels a run #971

Closed

Description

@OmarAlJarrah

Problem

morphic compile -o out.json writes through a temporary file in the destination's directory and renames it into place. At c387e25c:

  • a SIGINT that arrives while .out.json.tmp<16 hex> is being written leaves that file behind (4,405 bytes in one run, 1,036,005 in another), next to an untouched out.json;
  • a SIGINT earlier, while compiling, leaves nothing.

Cause

replaceFile removes its temporary file on its error returns only (cmd/morphic/compile.go). The CLI installs no signal handling and runs on context.Background() (cmd/morphic/main.go), so the engine's cancellation path has no caller outside tests.

Direction

A proposal:

  • signal.NotifyContext for SIGINT and SIGTERM in main, with the context passed to engine.Run.
  • replaceFile removes its temporary file when the context ends mid-write. A second signal still kills the process outright, so the name pattern stays recognisable for cleanup.

Done when a test sends SIGINT to the built binary during the write, driven from the test rather than a shell job (which starts with SIGINT ignored), and finds no temporary file and the destination unchanged.

Out of scope

How quickly the compile itself stops (#970).

Related: #791

Priority: P4, rule 3 (tooling; it does not touch the golden spec's output). SIGINT at the temporary file's first appearance → .out.json.tmp… left behind (morphic @c387e25c).

Metadata

Metadata

Assignees

No one assigned

    Labels

    priority:P4Refactors, tests, CI, hostile-input hardening, cosmetic diagnostics, other formatstype:bugDefect in shipped behavior

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions