Skip to content

http2: server.close not behaving like http1 or net #20630

Closed
@mcollina

Description

@mcollina
  • Version: 8, 9, 10, master
  • Platform: Mac OS X
  • Subsystem: http2

An http2 server inherits from net.Server, so a user might expect that the behavior of close() is the same (and we document it as being the same). However, the following will never call the close(cb)  callback.

'use strict';

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

const server = http2.createServer();
let client;

server.listen(0, function() {
  client = http2.connect(`http://localhost:${server.address().port}`);
  client.on('connect', function() {
    console.log('connect');

    server.close(function() {
      console.log('the close callback');
    });
  });
});

server.on('session', (s) => {
  s.setTimeout(10, function () {
    console.log('timeout');
    s.destroy();
  });
});

This is the same code for net that works as expected:

'use strict';

const net = require('net');
const assert = require('assert');

const server = net.createServer();
let client;

server.listen(0, function() {
  client = net.connect(server.address().port);
  client.on('connect', function() {
    console.log('connect');

    server.close(function() {
      console.log('the close callback');
    });
  });
});

server.on('connection', (s) => {
  s.setTimeout(10, function () {
    console.log('timeout');
    s.destroy();
  });
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    confirmed-bugIssues with confirmed bugs.http2Issues or PRs related to the http2 subsystem.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions