Wrangler is throwing "connection terminated unexpectedly" errors for my Postgres DB

I have an ongoing issue with Wrangler being weird about connecting to DBs from my machine. Today I've started getting Error: Connection terminated unexpectedly from Postgres. This only happens when using the DB within Wrangler. I have another, non-Wrangler app that connects to the same DB in the same way and via the same connection string, and it's fine. The DB is up, and showing no signs of issues. Here's the util my controllers call to connect to and run a query on my DB:
export const query = async (q, params) => {
const client = new Client({
connectionString: env[env.DB+'-db'].connectionString,
ssl: {rejectUnauthorized: false}
});
await client.connect();
const res = await client.query(q, params);
return res;
};
export const query = async (q, params) => {
const client = new Client({
connectionString: env[env.DB+'-db'].connectionString,
ssl: {rejectUnauthorized: false}
});
await client.connect();
const res = await client.query(q, params);
return res;
};
The DB connection string is in my TOML under [[Hyperdrive]]. If I console.log(client) right after connecting, it shows readyForQuery: true. But when I then run a query, I get this error. Sorry if this is not related to Wrangler but as I say, it's not happening in non-Wrangler setups with the same DB connection code. Any idea what might be up?
2 Replies
Jack
Jack5mo ago
Hey @Mitya, did you manage to find a solution for this, and where is your database hosted?
Mitya
Mitya5mo ago
It seems from chatting in #hyperdrive-beta that it was related to an acknowledged bug with HD regarding query caching. The solution for the time being was to disable caching. CF apparently pushed a fix for this a few days ago but I've not disabled caching to verify that. My DB is hosted on Heroku but in light of the above that seems to be irrelevant.