Skip to content

d1({ session: 'auto' }) causes Worker to hang indefinitely when global_fetch_strictly_public flag is set #1273

Description

@ahtlv

Description

First off — love the work on EmDash, the DX is genuinely great. This one took me a while to track down, so I'm sharing it here to save others the pain.

When using d1({ binding: 'DB', session: 'auto' }) combined with the global_fetch_strictly_public compatibility flag in wrangler.jsonc, every SSR request hangs indefinitely and eventually gets killed by the CF Worker timeout (~10s).

Environment

  • EmDash: 0.15.0
  • @emdash-cms/cloudflare: 0.15.0
  • Astro: 6.x with @astrojs/cloudflare adapter
  • Deployment: Cloudflare Workers (not Pages)

wrangler.jsonc

{
  "compatibility_flags": ["global_fetch_strictly_public", "nodejs_compat"],
  ...
}

astro.config.mjs

import { d1, r2, access, sandbox } from '@emdash-cms/cloudflare';

emdash({
  database: d1({ binding: 'DB', session: 'auto' }),
  // ...
})

Symptoms

  • All SSR routes hang and time out (~10s)
  • Static assets (served by ASSETS binding) work fine
  • /_emdash/* routes redirect correctly via CF Access
  • wrangler tail shows:
    • outcome: "canceled"
    • cpuTime: ~8ms (almost no CPU work done)
    • wallTime: ~10000ms
    • exceptions: []
    • logs: []
  • No errors in logs whatsoever — makes it very hard to diagnose

Root cause hypothesis

session: 'auto' uses binding.withSession() under the hood, which likely makes an internal Cloudflare HTTP call to initialize the D1 Sessions API. The global_fetch_strictly_public flag blocks connections to private/internal Cloudflare addresses, causing the call to hang silently until the Worker is killed.

Workaround

Change session: 'auto' to session: 'disabled':

database: d1({ binding: 'DB', session: 'disabled' })

This immediately fixes the hang — all SSR routes respond normally.

Suggestion

It would be great if EmDash could either:

  1. Document the incompatibility between session: 'auto' and global_fetch_strictly_public in the docs/README
  2. Add a timeout on session initialization with a clear error message instead of a silent hang
  3. Auto-detect the flag and fall back to session: 'disabled' automatically

Thanks for the great project — hope this helps someone!

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions