Skip to content

ingestor: 'send on closed channel' panic on SIGTERM when a watchdog force-reconnect is in flight #103

Description

@dborup

Problem

The ingestor can panic with send on closed channel on SIGTERM if an MQTT watchdog force-reconnect is in flight during shutdown.

Where

cmd/ingestor/mqtt_watchdog.go, in the force-reconnect path of the stall watchdog. The watchdog runs ForceReconnectFn in a goroutine and then calls emit(...) ("WATCHDOG reconnect attempt issued"). If shutdown closes the channel behind emit while that goroutine is still inside ForceReconnectFn, the later send panics.

Background

Suggested fix

  • Make the emit path shutdown-safe. For example:
    • use a context or done channel and select on it instead of sending to a possibly closed channel;
    • or stop and wait for in-flight force-reconnect goroutines before closing the channel.
  • Add a test that triggers a force-reconnect whose ForceReconnectFn blocks, shuts the watchdog down, then unblocks it. The test should assert no panic, and run under -race.

No behaviour change for normal operation is expected.

Activity

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

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions