Skip to content

Improve code quality: graceful shutdown and concurrency safety #17

Description

@hajnalmt

Context

The codebase has several code quality problems that should be addressed to bring it up to modern Go standards and make it production-ready for Kubernetes environments.

Problems

No Graceful Shutdown

The main loop runs forever with no signal handling. There is no way to catch SIGTERM/SIGINT for clean shutdown, cancel in-flight operations, or log shutdown events. This is problematic in Kubernetes where pods receive SIGTERM before being killed.

Global Mutable State Without Synchronization

  • numaMap (package-level map) is read and written without mutex protection
  • config (package-level var) is similarly unprotected
  • While currently single-goroutine, this is fragile and prevents future concurrency (e.g., adding an HTTP health endpoint)

Hardcoded Strings

  • Environment variable names like MY_NODE_NAME are used as magic strings in multiple files

Tasks

  • Implement graceful shutdown with signal.NotifyContext and context propagation
  • Add sync.RWMutex protection for package-level mutable state
  • Extract hardcoded strings into package-level constants
  • Improve error messages for missing configuration

Acceptance Criteria

  • Binary handles SIGTERM gracefully (logs shutdown, flushes, exits cleanly)
  • No data races detected by go test -race ./...
  • golangci-lint run ./... passes with zero issues

Priority

Medium — important for production Kubernetes deployments where pods receive SIGTERM during rolling updates, node drains, and scaling events.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions