Skip to content

add graceful signal handling and temp secret cleanup #32

@fabracht

Description

@fabracht

Problem

MQDB agent and cluster processes have no registered signal handlers for SIGINT/SIGTERM. The default handler kills the process immediately, skipping graceful shutdown.

This also means temp files created by the env var inline content feature (/tmp/mqdb-env-secrets-{PID}/) persist after process exit. On Docker this is irrelevant (ephemeral filesystem), but on bare metal, secrets (passwd, JWT keys, QUIC certs) sit in /tmp with 0o600 permissions until reboot.

Current state

  • MqdbAgent and ClusteredAgent both have internal shutdown_tx broadcast channels and graceful shutdown logic (awaiting spawned tasks)
  • The shutdown path only runs if broker.run() returns normally — signals bypass it entirely
  • The only signal handler in the codebase is in crud.rs for the watch command
  • Temp secret files use PID-scoped directories and 0o600 permissions (low risk, but not zero)

Proposed fix

Register tokio::signal::ctrl_c() + unix SIGTERM handler in both cmd_agent_start and cmd_cluster_start. On signal:

  1. Send shutdown via the existing shutdown_tx channel
  2. Await graceful task completion (already implemented)
  3. Remove the PID-scoped temp directory (/tmp/mqdb-env-secrets-{PID}/)

This solves both graceful shutdown and temp file cleanup in one change.

Files involved

  • crates/mqdb-cli/src/commands/agent.rscmd_agent_start
  • crates/mqdb-cli/src/commands/cluster.rscmd_cluster_start
  • crates/mqdb-cli/src/commands/env_secret.rs — add cleanup() function
  • crates/mqdb-agent/src/agent/mod.rs — expose shutdown() for external callers
  • crates/mqdb-cluster/src/cluster_agent/mod.rs — expose shutdown() for external callers

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions