Skip to content

Default email template is served for 10 minutes after one failed template fetch #2910

Open

Description

@mansur-akhmadi

Bug report

  • I confirm this is a bug with Supabase, not with my own application.
  • I confirm I have searched the Docs, GitHub Discussions, and Discord.

Describe the bug

With custom templates set through GOTRUE_MAILER_TEMPLATES_* URLs and template reloading off (the default), one failed fetch on a cold cache makes Auth send the built-in template for the next GOTRUE_MAILER_TEMPLATE_MAX_AGE (10m), even when the template server is back a few seconds later.

GOTRUE_MAILER_TEMPLATE_RETRY_INTERVAL (10s) doesn't help in this case. It only applies once the cached entry is older than the max age. That works when a previously fetched custom template fails to refresh, but not when the only thing in the cache is the default fallback.

The background reloader (GOTRUE_MAILER_TEMPLATE_RELOADING_ENABLED=true) retries the fallback after the retry interval, so the two modes disagree. The CLI enables reloading, so local dev mostly doesn't hit this. The self-hosting compose file doesn't, so self-hosted setups do.

In practice: restart the stack, the first sign-up arrives before the template server is reachable (or it returns a 5xx or times out once), and every confirmation email for the next 10 minutes uses the default template. The only trace is a single templatemailer_template_body_http_error log line.

To Reproduce

  1. Run Auth with a custom template URL and the default reloading setting:
    GOTRUE_MAILER_TEMPLATES_CONFIRMATION=http://templates-server/confirmation.html
    # GOTRUE_MAILER_TEMPLATE_RELOADING_ENABLED unset (false)
    
  2. Stop the template server (or make it return 503).
  3. Sign up a user. The confirmation email uses the default template (expected, the server is down).
  4. Start the template server again.
  5. Wait 15 seconds and sign up another user.
  6. The email still uses the default template. Custom templates only come back after about 10 minutes from step 3.

Expected behavior

After the fallback, the configured template is retried after GOTRUE_MAILER_TEMPLATE_RETRY_INTERVAL, the same as with background reloading enabled. Once it loads, it's cached for the max age as usual.

System information

  • Auth: master at 84ff0c0 (also in the supabase/gotrue:v2.197.0 image used by the self-hosting compose file)
  • Self-hosted, Docker Compose

Additional context

Related: #2153 (background template reloading) and #2783 (another way template fetches fail silently and fall back to the defaults).

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

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions