Hyperdrive fails to connect in `scheduled()` (but works over HTTP)
The same worker either will or won't connect to my Hyperdrive DB depending on whether I invoke it over HTTP (will) or CRON( won't). I'm experiencing this while testing locally, with the
--remote
flag enabled.
Specifically, I get:
In my DB handler, I put the following:
Over HTTP, I get:
Over CRON, I get (via the --test-scheduled
flag and the /__scheduled
endpoint):
Accordingly, DB queries work over HTTP but I get errors on CRON. Here's how I specify my DB in dev.toml
:
Here's what runs when I run npm run dev
:
Here's what then comes up (see image below). As you can see, my Hyperdrive DB is there.
Any help appreciated4 Replies
Hey wrangler dev with hyperdrive to a remote db is a known not working feature currently. Is this the scenario you are attempting?
Hi - could you possibly elaborate? This is the setup I've had for over a year and it works perfectly over HTTP?
From the docs:
To access your production (remote) Hyperdrive configuration, pass the --remote
flag
This is what I'm doing. My dev DB is remote, and is created as a HD, and I connect to it locally via --remote
.
Just to be clear, with the above setup:
Ah ok I misread that you were connecting over HTTP and not HTTPS. HTTPS scenario is what doesn't work currently. Hm ok I'll look at the --test-scheduled flag to see what is making it behave differently
Thanks, really appreciate it. If it helps, I used to get this error every time I made code changes while testing schedules, i.e. the next time I visited the
/__schedule
endpoint after Wrangler's HMR had uploaded the changes. I'd then refresh, and it would work fine. But that first time, after code changes, I'd always get this. Now suddenly I get it constantly.
There's definitely something fishy here; without any changes, everything just started working again i.e. the DB connected. I refresh, and it's back to the above error with CF saying it can't read the HD connection string. Refresh 10 more times, same error. On the 11th time, it works 🤷