Skip to content

Question: How come still TCPSERVERWRAP? #18

Description

@nottoseethesun

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
└── express@4.17.1 

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?

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions