kartikk221 / hyper-express

High performance Node.js webserver with a simple-to-use API powered by uWebsockets.js under the hood.
MIT License
1.73k stars 89 forks source link

[Bug] Error: Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse. #184

Closed masfahru closed 1 year ago

masfahru commented 1 year ago

Error

Error happening when client is aborting request

Error: Invalid access of discarded (invalid, deleted) uWS.HttpResponse/SSLHttpResponse.
    at Response.send (/home/fahru/Kerja/test-hyper/node_modules/hyper-express/src/components/http/Response.js:491:39)
    at Response.json (/home/fahru/Kerja/test-hyper/node_modules/hyper-express/src/components/http/Response.js:698:34)

Step to reproduce

  1. Init Nodejs app, install Hyper-Express 6.8.0

  2. Create index.js, add below code

import { Server } from 'hyper-express'

const delay = (t, val) => {
  return new Promise(function(resolve) {
      setTimeout(function() {
          resolve(val);
      }, t);
  });
}

const someAsyncTask = async () => {
  return delay(2000, 'Hey wait for me!');
}

const webserver = new Server()

webserver.get('/', async (_request, response) => {
  const r = await someAsyncTask();
  response.json({ message: r })
})

webserver.listen(3000)
  1. Start the server using node index.js
  2. curl "http://127.0.0.1:3000/" and abort the request before it return response

The error is happened in version 6.8.0 Screenshot_20230727_104721

Tested in version 6.7.1 and it's working fine image

Able to prevent the in version 6.8.0 if the response.json is wrapped using response atomic:

webserver.get('/', async (_request, response) => {
  const r = await someAsyncTask();
  response.atomic(()=>{
    response.json({ message: r })
  })
})

Screenshot_20230727_104811

kartikk221 commented 1 year ago

This bug has been fixed in the recently released v6.8.1 update. Be sure to update with npm and let me know If that resolves your problem. Thanks!

masfahru commented 1 year ago

This bug has been fixed in the recently released v6.8.1 update. Be sure to update with npm and let me know If that resolves your problem. Thanks!

It's been solved, thank you !