Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Query hangs when used as express middleware #941

Open
ext4cats opened this issue Sep 11, 2024 · 1 comment
Open

Query hangs when used as express middleware #941

ext4cats opened this issue Sep 11, 2024 · 1 comment

Comments

@ext4cats
Copy link

ext4cats commented Sep 11, 2024

I've been trying to use this library as an express middleware, for dependency injection convenience.

But I ran into a roadblock; queries get stuck seemingly forever when I do this. I am not sure why this happens? I've tested the code over and over and the issue persists. I moved off my production project to try reproducing it and was able to do it.

Here's some sample code, running on Node LTS with Postgres.js 3.4.4 and Express 4.20.0.

import express from 'express';
import postgres from 'postgres';

function createExpressApp() {
  const app = express();
  app.use(databaseMiddleware());
  app.get('/', testHandler);
  return app;
}

const databaseMiddleware = () => {
  const sql = postgres(
    'postgresql://postgres:postgres@localhost:8080/postgres',
  );
  return (req, res, next) => {
    req.sql = sql;
    next();
  };
};

const testHandler = async (req, res, next) => {
  try {
    const response = await req.sql`SELECT version()`;
    res.status(200).json(response);
  } catch (err) {
    next(err);
  }
};

createExpressApp().listen(8080, () => console.log("listenin'"));

I hope this gets fixed if it really is a bug; feels like a shame to not be able to use such a nice library because of such an obnoxious issue.

@ext4cats
Copy link
Author

ext4cats commented Sep 11, 2024

The closest related issue I could find is #747, which was posted November last year and is still open. Gotta say, it doesn't give me a lot of hope...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant