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.

With http2 "socket hang up"

See original GitHub issue

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

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:6 (1 by maintainers)

github_iconTop GitHub Comments

1reaction
lamweilicommented, 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
0reactions
titanismcommented, Oct 4, 2022

Closed via https://github.com/visionmedia/supertest/pull/793 and released in v6.3.0

Read more comments on GitHub >

github_iconTop Results From Across the Web

Node.js HTTP2 server Error: socket hang up - Stack Overflow
The "hang" occurs when a HTTP1 client connects to a HTTP/2 server with allowHTTP1: true set but doesn't handle the HTTP/1 request.
Read more >
Error: socket hang up with 15.7.0 or newer · Issue #37510
I filled it with free socks5 proxy. const request = require('request'); const Agent = require('socks5-https-client/lib/Agent'); let ip = { url ...
Read more >
NodeJS - What does socket hang up actually mean - Edureka
When a socket hang up is thrown, one of two things happens: When you're a customer, When you send a request to a...
Read more >
Socket hang up problems - Google Groups
Hi, I've been getting this issue every now and then on a long poll request. It doesn't happen consistently so I'm finding it...
Read more >
502 Bad Gateway - Socket hang up | Apigee Edge
The error code [socket hang up][ECONNRESET] indicates that the target server has closed the connection with Edge Microgateway. This can be ...
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