http-terminator icon indicating copy to clipboard operation
http-terminator copied to clipboard

Question: How come still `TCPSERVERWRAP`?

Open nottoseethesun opened this issue 5 years ago • 0 comments

With simple usage just as with the express example on the README, the express listener is still running from the return statement in the snippet from node_modules/express/lib/application.js below:

app.listen = function listen() {
  var server = http.createServer(this);
  return server.listen.apply(server, arguments);
};

I've verified that I only have one instance of express listening, by putting an unmistakeable console.log just before that return statement above.

$ node --version
v14.11.0

$ npm ls express
redacted-package
└── [email protected] 

The problem is:

Jest has detected the following 1 open handle potentially keeping Jest from exiting:

  ●  TCPSERVERWRAP



      at Function.listen (../node_modules/express/lib/application.js:618:24)
      at Object.<anonymous> (index.ts:1195:32)

The app that won't stop (only the relevant parts are pasted):


import express from "express";

const app = express();

const server: Server = app.listen(port, () =>
  logger.info(`Listening on port ${port}...`),
);

module.exports = server;
import { createHttpTerminator, HttpTerminator } from 'http-terminator';

let server: Server;
let httpTerminator: HttpTerminator;

describe("/", () => {
  beforeEach(async () => {
    server = require("../../../index"); // This is the file shown in the block above
    httpTerminator = createHttpTerminator({
      gracefulTerminationTimeout: 0,
      server,
    });
    void (await redactedPromiseReturner());
  });

  afterEach(async () => {    
    void (await httpTerminator.terminate());
  });

What are some troubleshooting tips?

nottoseethesun avatar Sep 18 '20 03:09 nottoseethesun