Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

With http2 "socket hang up" #617

Closed
crystalfp opened this issue Jan 22, 2020 · 6 comments
Closed

With http2 "socket hang up" #617

crystalfp opened this issue Jan 22, 2020 · 6 comments

Comments

@crystalfp
Copy link

I'm using supertest on Windows 10 and node 12.14.1 with great satisfaction.
However, if I switch my server to http2 all tests fail. They prints only socket hang up and nothing more. My server is Koa and tests are written with typescript. Here is an excerpt:

import http2 from "http2";

const app = new Koa();
const options = {
	key:  fs.readFileSync(path.join(__dirname, "cert", "privkey.pem")),
	cert: fs.readFileSync(path.join(__dirname, "cert", "cert.pem"))
};

const server = http2
			.createSecureServer(options, app.callback())
			.once("error", handleServerErrors)
			.listen(3111, () => runApp("https"));

request = supertest(server);

Any ideas? Everything runs smoothly if I use http and createServer()

Thanks!
mario

@crystalfp
Copy link
Author

Someone suggested to use .trustLocalhost() from superagent, but I don't know where to attach it.

@lddubeau
Copy link

lddubeau commented Feb 1, 2020

I'm using fastify and ran into the same problem when I turned on http2. I then turned it off but kept https configured and that worked. At this point I'm thinking that the issue is http2, not https itself.

The only difference from when I ran the tests only with http is that I used the environment variable NODE_EXTRA_CA_CERTS=... to point to the self-signed certificate I created for testing.

I also used the .ca call provided through superagent, and that worked after I turned off http2, but I would have had to add it to all tests. NODE_EXTRA_CA_CERTS= take care of the whole test suite in one fell swoop.

@crystalfp
Copy link
Author

Unfortunately, defining NODE_EXTRA_CA_CERTS before tests changes nothing. All tests fail with socket hang up as before.

@crystalfp
Copy link
Author

Dear @lddubeau,
could you share your code? I'm lost on how to turn off http2 maintaining https.
My real code is like the one I posted. Simply based on a variable useHTTP2 I run the code above or a code running http. If someone thinks it is relevant, I could post a minimal example.
Thanks!
mario

@lamweili
Copy link
Contributor

lamweili commented Oct 4, 2022

Given the date of this issue, it should be supertest@<=5.0.0-0.
Back then, http2 wasn't supported by supertest.


Nevertheless, this http2 feature has been incorporated into supertest@6.3.0 (PR #793).
A sample code snippet is in the README.md.

Based on your code, I would reckon it would be something like:

const request = require('supertest');

const options = {
  key:  fs.readFileSync(path.join(__dirname, "cert", "privkey.pem")),
  cert: fs.readFileSync(path.join(__dirname, "cert", "cert.pem"))
};
const app = function(req, res) {
  res.end('hey');
};
const server = http2.createSecureServer(options, app);
// either
request(server)       // pass in your http2 server
  .get('/')
  .http2()            // https://visionmedia.github.io/superagent/#using-http/2
  .disableTLSCerts(); // https://visionmedia.github.io/superagent/#tls-options

// or
request(server)       // pass in your http2 server
  .get('/')
  .http2()            // https://visionmedia.github.io/superagent/#using-http/2
  .trustLocalhost();  // https://visionmedia.github.io/superagent/#testing-on-localhost

@titanism
Copy link
Collaborator

titanism commented Oct 4, 2022

Closed via #793 and released in v6.3.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants