nginx / unit

NGINX Unit - universal web app server - a lightweight and versatile open source server that simplifies the application stack by natively executing application code across eight different programming language runtimes.
https://unit.nginx.org
Apache License 2.0
5.27k stars 322 forks source link

nodejs unit-http misses close()? #1061

Open kbzowski opened 5 months ago

kbzowski commented 5 months ago

I have notice that during shutdown of NestJS based application which uses express internally I got an error:

TypeError: this.httpServer.close is not a function
   at /app/server/node_modules/@nestjs/platform-express/adapters/express-adapter.js:96:55
   at new Promise .new Promise (<anonymous> undefined)
   at ExpressAdapter.close (/app/server/node_modules/@nestjs/platform-express/adapters/express-adapter.js:96:16 undefined)   
   at NestApplication.dispose (/app/server/node_modules/@nestjs/core/nest-application.js:47:53 undefined)
   at async process.cleanup (/app/server/node_modules/@nestjs/core/nest-application-context.js:189:1

Origin of the error is the close() function https://github.com/nestjs/nest/blob/master/packages/platform-express/adapters/express-adapter.ts#L160 which calls http.close(). As far as I can see unit does not implement this function. Correct me please if I don't understand something.

tippexs commented 5 months ago

Hi @kbzowski Sorry for the delayed response! @andrey-zelenkov Can you have a look at this, please as you have worked with some of the NodeJS fixes before.

dbit-xia commented 5 months ago

I also found that after SIGINT, the server's 'close' event will be automatically executed, it didn't wait for all my requests to finish; instead, it directly interrupted the requests.

For applications that require a graceful exit, it is advisable to support manual closure.

https://nodejs.org/dist/latest/docs/api/net.html#serverclosecallback image

server.on('close', () => {
  console.log('server closed');
});