- 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();
});
});
An http2 server inherits from
net.Server, so a user might expect that the behavior ofclose()is the same (and we document it as being the same). However, the following will never call theclose(cb)callback.This is the same code for
netthat works as expected: