hyper-express: Multiple Middleware on Route Hangs

Hey @kartikk221!

I rolled out my new micro services backed by hyper-express and our recent changes and I noticed a bug. I’m trying to track it down, but I might need to tag you in as you are more familiar with this change.

When you define middleware on a specific route, it seems like every other request hangs and eventually fails. Here is a quick and easy reproduction. We should add this to the tests.

import { 
  Server,
  type Request,
  type Response,
  type MiddlewareNext
} from 'hyper-express'

const app = new Server()

app.post(
  '/echo',
  async (req: Request, res: Response, next: MiddlewareNext) => {
    req.body = await req.json()
    next()
  },
 (req: Request, res: Response, next: MiddlewareNext) => {
    res.locals.data = req.body
    next()
  },
 (req: Request, res: Response) => {
    res.status(200).json(res.locals.data)
  }
)

app.listen(3000)

Then if you use Postman to POST to localhost:3000/echo with a request body:

{ "foo": "bar" }

Every other request hangs. Oddly this doesn’t happen when you curl which leads me to believe that the socket isn’t being closed on the server side.

Any insight?

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Comments: 35 (34 by maintainers)

Most upvoted comments

We should definitely do that as well. Im sure @alexhultman would appreciate it.

I’m working on a mac at the moment which is also unix. I will try to fix it, in the mean time can you run that script locally and hit it with postman?