question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

How to gracefully shutdown the server? (tests are failing)

See original GitHub issue

I write some tests and I cannot get the proxy gracefully shutdown.

My test is very simple:

it('should start the server', async () => {
  const server = await proxy(8000);
  await delay(1000);
  await server.stop();
});

where proxy() is an async function having this:

  await server.start(port);
  return server;

Now when I run my tests as $ npm run test -- -t 'should start the server' --detectOpenHandles I get this:

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

  ●  JSSTREAM

      1 | import fs from 'fs';
      2 | import { basename, join, resolve } from 'path';
    > 3 | import { getLocal, generateCACertificate, generateSPKIFingerprint, RequestRuleBuilder } from 'mockttp';
        | ^
      4 |
      5 | import { ResolvedManifest } from './model';
      6 | import { fileExists, ManifestError, readFile, readManifest, saveFile } from './service';

      at Object.<anonymous> (node_modules/http2-wrapper/source/utils/js-stream-socket.js:6:25)
      at Object.<anonymous> (node_modules/http2-wrapper/source/proxies/h1-over-h2.js:3:24)
      at Object.<anonymous> (node_modules/http2-wrapper/source/index.js:13:5)
      at Object.<anonymous> (node_modules/mockttp/src/rules/requests/request-handlers.ts:8:1)
      at Object.<anonymous> (node_modules/mockttp/src/rules/requests/request-rule.ts:10:1)
      at Object.<anonymous> (node_modules/mockttp/src/server/mockttp-server.ts:28:1)
      at Object.<anonymous> (node_modules/mockttp/src/main.ts:2:1)
      at Object.<anonymous> (src/proxy.ts:3:1)
      at Object.<anonymous> (src/proxy.test.ts:1:1)

What can I do about this?

P.S. Here is my proxy code: https://github.com/OnkelTem/wmod-proxy/blob/master/src/proxy.ts just for reference.

Issue Analytics

  • State:open
  • Created a year ago
  • Comments:10 (4 by maintainers)

github_iconTop GitHub Comments

2reactions
pimterrycommented, May 16, 2022

That’s surprising. It sounds like this is caused by some HTTP/2 connection that’s staying open. HTTP/2 support is a bit experimental in places, and I can definitely believe that there’s some cases where pooled connections aren’t shut down as aggressively as intended. I’d definitely like to tighten up this kind of thing though.

That said, it’s a bit unusual that HTTP/2 is being used here at all. Because it’s experimental, Mockttp uses ALPN to actively avoid it where possible - by default it’s only used for clients who connect and say they only support HTTP/2, not HTTP/1 (those exist, notably in clients using gRPC, but it’s not common). One quick fix option might be to just disable HTTP/2 - you can do that by passing a http2: false option to getLocal() (docs). Is HTTP/2 important for your setup?

1reaction
pmpakcommented, Jun 3, 2022

I was trying quite a lot to make this error go away until I stumbled upon this issue. Setting {http2: false} worked like a charm. thanks a lot !

Read more comments on GitHub >

github_iconTop Results From Across the Web

Testing graceful shutdown on an HTTP server during a ...
To verify that, I started performing load tests (using Apache Benchmark, by running ab -n 100000 -c 20 <addr> ) and running kubectl...
Read more >
Testing graceful http server shutdown that uses channels and ...
Technically it boots up http server and shuts down gracefully if signal is received. How do I test this please?
Read more >
Make Sure Your Disaster Recovery Plan Isn't Just Words on ...
Failover test. Simulate a production outage by gracefully shutting down the primary servers and failing over to the secondary site. This test ......
Read more >
How to terminate a test that won't stop
Pressing the stop button prompts to either do a graceful shutdown or terminate the servers, as explained in this article.
Read more >
Gracefully clean up in gRPC JUnit tests
shutdownNow (); server.shutdownNow(); // fail the test if cleanup is not successful assert channel.awaitTermination(5, TimeUnit.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found