HTTP/2 settings request was cancelled
Production Risk
Low — handle the callback error to avoid silent failures.
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.
- 1Session destroyed while a settings() call was awaiting acknowledgment
- 2A second settings() call made before the first was acknowledged
- 3Network timeout causing the SETTINGS ACK to never arrive
Triggered when an outstanding SETTINGS callback is cancelled due to session closure or a superseding SETTINGS.
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 ackexpected 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
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.
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_CANCELtry {
// 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
}
}// Validate inputs before calling the operation
function safe_err_http2_settings_cancel(...args) {
// validate args here
return performOperation(...args)
}✕ Destroy sessions immediately after calling settings()
The settings callback is cancelled when the session closes.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev