Search code examples
node.jshttptcpdnshttp2

HTTP2 DNS lookup on existing connection


I have a code sample from node.js api docs:

const http2 = require('http2');
const fs = require('fs');

const client = http2.connect('https://localhost:8443', {
  ca: fs.readFileSync('localhost-cert.pem')
});

client.on('error', (err) => console.error(err));

Having the connection established, I'd like to know if it's going to do DNS lookup every next request via an existing connection.


Solution

  • Via an existing connection no, there is no need to look up the DNS again. That only happens at the start of the connection. In the same way as under HTTP/1.1 when reusing a connection.

    However, exactly as under HTTP/1.1, there is no guarantee the connection will be kept open and it can be closed at any time by either the client, the server or just by a network glitch in between. So if your code automatically reconnects in this scenario then it may do another DNS lookup.