ERR_HTTP2_SETTINGS_CANCEL
Node.jsERRORCriticalHTTP/2HIGH confidence

HTTP/2 settings request was cancelled

Production Risk

Low — handle the callback error to avoid silent failures.

What this means

Thrown when an HTTP/2 SETTINGS frame acknowledgment is not received before the session is destroyed or before a new SETTINGS frame is sent. The pending settings callback is cancelled in these circumstances.

Why it happens
  1. 1Session destroyed while a settings() call was awaiting acknowledgment
  2. 2A second settings() call made before the first was acknowledged
  3. 3Network timeout causing the SETTINGS ACK to never arrive
How to reproduce

Triggered when an outstanding SETTINGS callback is cancelled due to session closure or a superseding SETTINGS.

trigger — this will error
trigger — this will error
const session = http2.connect('https://localhost:3000');
session.settings({ headerTableSize: 4096 }, (err) => {
  if (err) console.error(err.code); // ERR_HTTP2_SETTINGS_CANCEL
});
session.destroy(); // cancels pending ack

expected output

Error [ERR_HTTP2_SETTINGS_CANCEL]: HTTP2 session settings canceled

Fix

Destroy the session only after settings are acknowledged

WHEN When changing settings before closing a session

Destroy the session only after settings are acknowledged
session.settings({ headerTableSize: 4096 }, (err) => {
  if (err) return console.error('Settings failed:', err);
  session.destroy();
});

Why this works

Waiting for the callback ensures the SETTINGS ACK is received before teardown.

Code examples
Triggerjs
const session = http2.connect('https://localhost:3000');
session.settings({ headerTableSize: 4096 }, (err) => {
  if (err) console.error(err.code); // ERR_HTTP2_SETTINGS_CANCEL
});
session.destroy(); // cancels pending ack  // this triggers ERR_HTTP2_SETTINGS_CANCEL
Handle in try/catchjs
try {
  // operation that may throw ERR_HTTP2_SETTINGS_CANCEL
  riskyOperation()
} catch (err) {
  if (err.code === 'ERR_HTTP2_SETTINGS_CANCEL') {
    console.error('ERR_HTTP2_SETTINGS_CANCEL:', err.message)
  } else {
    throw err
  }
}
Defensive pattern to avoid itjs
// Validate inputs before calling the operation
function safe_err_http2_settings_cancel(...args) {
  // validate args here
  return performOperation(...args)
}
What not to do

Destroy sessions immediately after calling settings()

The settings callback is cancelled when the session closes.

Same error in other languages
Sources
Official documentation ↗

Node.js Error Codes Documentation

Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev

← All Node.js errors