Wrangler is throwing "connection terminated unexpe...
# workers-help
m
I have an [ongoing issue](https://discord.com/channels/595317990191398933/1185199329317765231) 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:
Copy code
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?
j
Hey @mitya2364, did you manage to find a solution for this, and where is your database hosted?
m
It seems from chatting in #1150557986239021106 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.