11cb0ef41Sopenharmony_ci// Flags: --expose-internals 21cb0ef41Sopenharmony_ci'use strict'; 31cb0ef41Sopenharmony_ci 41cb0ef41Sopenharmony_ciconst common = require('../common'); 51cb0ef41Sopenharmony_ciif (!common.hasCrypto) common.skip('missing crypto'); 61cb0ef41Sopenharmony_ciconst h2 = require('http2'); 71cb0ef41Sopenharmony_ciconst assert = require('assert'); 81cb0ef41Sopenharmony_ciconst { ServerHttp2Session } = require('internal/http2/core'); 91cb0ef41Sopenharmony_ci 101cb0ef41Sopenharmony_ciconst server = h2.createServer(); 111cb0ef41Sopenharmony_ci 121cb0ef41Sopenharmony_ciserver.on('stream', common.mustNotCall()); 131cb0ef41Sopenharmony_ciserver.on('error', common.mustNotCall()); 141cb0ef41Sopenharmony_ci 151cb0ef41Sopenharmony_ciserver.listen(0, common.mustCall(() => { 161cb0ef41Sopenharmony_ci 171cb0ef41Sopenharmony_ci // Setting the maxSendHeaderBlockLength > nghttp2 threshold 181cb0ef41Sopenharmony_ci // cause a 'sessionError' and no memory leak when session destroy 191cb0ef41Sopenharmony_ci const options = { 201cb0ef41Sopenharmony_ci maxSendHeaderBlockLength: 100000 211cb0ef41Sopenharmony_ci }; 221cb0ef41Sopenharmony_ci 231cb0ef41Sopenharmony_ci const client = h2.connect(`http://localhost:${server.address().port}`, 241cb0ef41Sopenharmony_ci options); 251cb0ef41Sopenharmony_ci client.on('error', common.expectsError({ 261cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_SESSION_ERROR', 271cb0ef41Sopenharmony_ci name: 'Error', 281cb0ef41Sopenharmony_ci message: 'Session closed with error code 9' 291cb0ef41Sopenharmony_ci })); 301cb0ef41Sopenharmony_ci 311cb0ef41Sopenharmony_ci const req = client.request({ 321cb0ef41Sopenharmony_ci // Greater than 65536 bytes 331cb0ef41Sopenharmony_ci 'test-header': 'A'.repeat(90000) 341cb0ef41Sopenharmony_ci }); 351cb0ef41Sopenharmony_ci req.on('response', common.mustNotCall()); 361cb0ef41Sopenharmony_ci 371cb0ef41Sopenharmony_ci req.on('close', common.mustCall(() => { 381cb0ef41Sopenharmony_ci client.close(); 391cb0ef41Sopenharmony_ci server.close(); 401cb0ef41Sopenharmony_ci })); 411cb0ef41Sopenharmony_ci 421cb0ef41Sopenharmony_ci req.on('error', common.expectsError({ 431cb0ef41Sopenharmony_ci code: 'ERR_HTTP2_SESSION_ERROR', 441cb0ef41Sopenharmony_ci name: 'Error', 451cb0ef41Sopenharmony_ci message: 'Session closed with error code 9' 461cb0ef41Sopenharmony_ci })); 471cb0ef41Sopenharmony_ci req.end(); 481cb0ef41Sopenharmony_ci})); 491cb0ef41Sopenharmony_ci 501cb0ef41Sopenharmony_ci{ 511cb0ef41Sopenharmony_ci const options = { 521cb0ef41Sopenharmony_ci maxSendHeaderBlockLength: 100000, 531cb0ef41Sopenharmony_ci }; 541cb0ef41Sopenharmony_ci 551cb0ef41Sopenharmony_ci const server = h2.createServer(options); 561cb0ef41Sopenharmony_ci 571cb0ef41Sopenharmony_ci server.on('error', common.mustNotCall()); 581cb0ef41Sopenharmony_ci server.on( 591cb0ef41Sopenharmony_ci 'session', 601cb0ef41Sopenharmony_ci common.mustCall((session) => { 611cb0ef41Sopenharmony_ci assert.strictEqual(session instanceof ServerHttp2Session, true); 621cb0ef41Sopenharmony_ci }), 631cb0ef41Sopenharmony_ci ); 641cb0ef41Sopenharmony_ci server.on( 651cb0ef41Sopenharmony_ci 'stream', 661cb0ef41Sopenharmony_ci common.mustCall((stream) => { 671cb0ef41Sopenharmony_ci stream.additionalHeaders({ 681cb0ef41Sopenharmony_ci // Greater than 65536 bytes 691cb0ef41Sopenharmony_ci 'test-header': 'A'.repeat(90000), 701cb0ef41Sopenharmony_ci }); 711cb0ef41Sopenharmony_ci stream.respond(); 721cb0ef41Sopenharmony_ci stream.end(); 731cb0ef41Sopenharmony_ci }), 741cb0ef41Sopenharmony_ci ); 751cb0ef41Sopenharmony_ci 761cb0ef41Sopenharmony_ci server.on( 771cb0ef41Sopenharmony_ci 'sessionError', 781cb0ef41Sopenharmony_ci common.mustCall((err, session) => { 791cb0ef41Sopenharmony_ci assert.strictEqual(err.code, 'ERR_HTTP2_SESSION_ERROR'); 801cb0ef41Sopenharmony_ci assert.strictEqual(err.name, 'Error'); 811cb0ef41Sopenharmony_ci assert.strictEqual(err.message, 'Session closed with error code 9'); 821cb0ef41Sopenharmony_ci assert.strictEqual(session instanceof ServerHttp2Session, true); 831cb0ef41Sopenharmony_ci server.close(); 841cb0ef41Sopenharmony_ci }), 851cb0ef41Sopenharmony_ci ); 861cb0ef41Sopenharmony_ci 871cb0ef41Sopenharmony_ci server.listen( 881cb0ef41Sopenharmony_ci 0, 891cb0ef41Sopenharmony_ci common.mustCall(() => { 901cb0ef41Sopenharmony_ci const client = h2.connect(`http://localhost:${server.address().port}`); 911cb0ef41Sopenharmony_ci client.on('error', common.mustNotCall()); 921cb0ef41Sopenharmony_ci 931cb0ef41Sopenharmony_ci const req = client.request(); 941cb0ef41Sopenharmony_ci req.on('response', common.mustNotCall()); 951cb0ef41Sopenharmony_ci req.on('error', common.mustNotCall()); 961cb0ef41Sopenharmony_ci req.end(); 971cb0ef41Sopenharmony_ci }), 981cb0ef41Sopenharmony_ci ); 991cb0ef41Sopenharmony_ci} 100