Skip to content

panic: nil map in alertmanager email.New() — EmailConfig.Headers not initialized #11100

@justinb-dfw

Description

@justinb-dfw

Bug Report

Root Cause: notify/email/email.go, function New() (line ~54-58), accesses the c.Headers map without first checking if it is nil. When an EmailConfig is created programmatically by the query-service pushing channel config via /api/v1/routes without an explicit headers: YAML field, Headers is a nil map[string]string. Map reads succeed (returning zero value + false), but the subsequent map writes panic.

Stack trace:

http: panic serving: assignment to entry in nil map
github.com/prometheus/alertmanager/notify/email.New(...)
        /app/notify/email/email.go:55

Buggy code in notify/email/email.go lines 54-65:

func New(c *config.EmailConfig, t *template.Template, l log.Logger) *Email {
    if _, ok := c.Headers["Subject"]; !ok {    // panics if c.Headers is nil
        c.Headers["Subject"] = config.DefaultEmailSubject
    }
    if _, ok := c.Headers["To"]; !ok {
        c.Headers["To"] = c.To
    }
    if _, ok := c.Headers["From"]; !ok {
        c.Headers["From"] = c.From
    }
    ...
}

Fix — one-line nil guard before first map access:

func New(c *config.EmailConfig, t *template.Template, l log.Logger) *Email {
    if c.Headers == nil {
        c.Headers = make(map[string]string)
    }
    if _, ok := c.Headers["Subject"]; !ok {
        c.Headers["Subject"] = config.DefaultEmailSubject
    }
    ...
}

Reproduction:

  1. Deploy SigNoz with alertmanager signoz/alertmanager:latest (v0.23.9)
  2. Create an email notification channel via SigNoz UI (Settings → Alert Channels)
  3. Click Test — query-service returns 500, alertmanager pod logs show the panic above

Workaround until fixed: Pre-configure the alertmanager alertmanager.yml with a default receiver containing an explicit headers: block so the Headers map is initialized from YAML deserialization rather than being nil.

Environment: signoz/alertmanager:latest (v0.23.9), linux/arm64 and amd64, triggered via /api/v1/testReceiver endpoint.

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