Repository: nodejs/node
File: lib/internal/http2/core.js (JavaScript)

Code before:
class Http2SecureServer extends TLSServer {
  constructor(options, requestListener) {
    options = initializeTLSOptions(options);
    super(options, connectionListener);
    this[kOptions] = options;
    this[kSessions] = new SafeSet();
    this.timeout = 0;
    this.on('newListener', setupCompat);
    if (options.allowHTTP1 === true) {
      this.headersTimeout = 60_000; // Minimum between 60 seconds or requestTimeout
      this.requestTimeout = 300_000; // 5 minutes
      this.connectionsCheckingInterval = 30_000; // 30 seconds
      const keepAliveTimeout = options.keepAliveTimeout;
      if (keepAliveTimeout !== undefined) {
        validateInteger(keepAliveTimeout, 'keepAliveTimeout', 0);
        this.keepAliveTimeout = keepAliveTimeout;
      } else {
        this.keepAliveTimeout = 5_000; // 5 seconds;
      }
      const keepAliveTimeoutBuffer = options.keepAliveTimeoutBuffer;
      // Optional buffer added to the keep-alive timeout when setting socket timeouts.
      // Helps reduce ECONNRESET errors from clients by extending the internal timeout.
      // Default is 1000ms if not specified.
      const buf = keepAliveTimeoutBuffer;
      this.keepAliveTimeoutBuffer =
        (typeof buf === 'number' && NumberIsFinite(buf) && buf >= 0) ? buf : 1000;
      this.shouldUpgradeCallback = function() {
        return this.listenerCount('upgrade') > 0;
      };
      this.on('listening', setupConnectionsTracking);
    }
    if (typeof requestListener === 'function')
      this.on('request', requestListener);
    this.on('tlsClientError', onErrorSecureServerSession);
  }

  setTimeout(msecs, callback) {
    this.timeout = msecs;
    if (callback !== undefined) {
      validateFunction(callback, 'callback');
      this.on('timeout', callback);
    }
    return this;
  }

  updateSettings(settings) {
    assertIsObject(settings, 'settings');
    validateSettings(settings);
    this[kOptions].settings = { ...this[kOptions].settings, ...settings };
  }


Review comment (suggestion):
We could also use `validateInteger` here, which is also the behaviour of the HTTP 1.1 implementation

Code after:

/**
 * This function closes all active sessions gracefully.
 * @param {*} server the underlying server whose sessions to be closed
 */
function closeAllSessions(server) {
  const sessions = server[kSessions];
  if (sessions.size > 0) {
    for (const session of sessions) {
      session.close();
    }
  }
}

class Http2SecureServer extends TLSServer {
  constructor(options, requestListener) {
    options = initializeTLSOptions(options);
    super(options, connectionListener);
    this[kOptions] = options;
    this[kSessions] = new SafeSet();
    this.timeout = 0;
    this.on('newListener', setupCompat);
    if (options.allowHTTP1 === true) {
      storeHTTPOptions.call(this, { ...options, ...options.http1Options });
      this.shouldUpgradeCallback = function() {
        return this.listenerCount('upgrade') > 0;
      };
      this.on('listening', setupConnectionsTracking);
    }
    if (typeof requestListener === 'function')
      this.on('request', requestListener);
    this.on('tlsClientError', onErrorSecureServerSession);
  }

  setTimeout(msecs, callback) {
    this.timeout = msecs;
    if (callback !== undefined) {
      validateFunction(callback, 'callback');
      this.on('timeout', callback);
    }
    return this;
  }

  updateSettings(settings) {
    assertIsObject(settings, 'settings');
    validateSettings(settings);
    this[kOptions].settings = { ...this[kOptions].settings, ...settings };
  }

  close() {
    ReflectApply(TLSServer.prototype.close, this, arguments);