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

Http connection ends after async operation in Express #131

Open
lastmjs opened this issue Jan 26, 2024 · 0 comments
Open

Http connection ends after async operation in Express #131

lastmjs opened this issue Jan 26, 2024 · 0 comments

Comments

@lastmjs
Copy link

lastmjs commented Jan 26, 2024

This bug was a bit difficult to track down. Essentially in Express.js if you use the text or json body parser middleware, and you have an asynchronous operation in your middleware callback before responding, you will never respond.

I've tracked it down to right here: https://github.com/second-state/wasmedge-quickjs/blob/main/modules/http.js#L565

I've commented out that code in my own fork. It seems that because the stream is auto destroyed, this happens perhaps in the next tick or something after being completely read, thus when the promise returns the http connection has been ended...maybe it's something with how I have my event loop setup? I think I have it pretty good though, I execute a function, poll the promises, then execute macro tasks and immediately poll promises after each tick task execution until there are no more macro tasks.

Here's an example similar to what did not work before commenting out that code:

app.use(express.text());

app.post('/', async (req, res) => {
  await test();
  res.send('Finished');
});

async test() {
  console.log('test');
}

If your request has the content type set appropriately to text/plain then this request will never finish.

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