gajus / gajus/http-terminator

Question: How come still `TCPSERVERWRAP`?

Open
#18 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
335
Forks
29
PR merge metrics
No merged PRs in 30d

Description

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:

```javascript
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.

```bash
$ node --version
v14.11.0

$ npm ls express
redacted-package
└── express@4.17.1
```

The problem is:

```bash
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. (index.ts:1195:32)
```

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

```typescript

import express from "express";

const app = express();

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

module.exports = server;
```

```typescript
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?

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.