TLS renegotiation request failed
Production Risk
Security-sensitive — renegotiation failure for client auth must be handled by terminating the connection.
Thrown when a TLS renegotiation attempt initiated by tlsSocket.renegotiate() fails. The failure may be due to the peer refusing the renegotiation, network interruption, or TLS protocol errors during the renegotiation handshake.
- 1The remote peer refused or did not respond to the renegotiation
- 2Network error interrupted the renegotiation handshake
- 3The socket was destroyed before renegotiation could complete
Triggered when the renegotiation callback receives an error from the TLS handshake.
const tls = require('tls');
const socket = tls.connect({ host: 'example.com', port: 443 }, () => {
socket.renegotiate({ rejectUnauthorized: true }, (err) => {
if (err) console.error(err.code); // ERR_TLS_RENEGOTIATION_FAILED
});
});expected output
Error [ERR_TLS_RENEGOTIATION_FAILED]: Failed to renegotiate
Fix 1
Establish a new TLS connection instead of renegotiating
WHEN When you need updated TLS parameters
// Close the current socket and open a new one with updated options
socket.destroy();
const newSocket = tls.connect({ host: 'example.com', port: 443, /* new options */ });Why this works
A fresh TLS connection avoids renegotiation entirely and is more reliable.
Fix 2
Handle renegotiation failure gracefully in the callback
WHEN When renegotiation is used for client certificate verification
socket.renegotiate({ requestCert: true }, (err) => {
if (err) {
socket.destroy(new Error('Client auth failed'));
return;
}
// proceed with authenticated socket
});Why this works
Destroying the socket on failure prevents unauthenticated access.
const tls = require('tls');
const socket = tls.connect({ host: 'example.com', port: 443 }, () => {
socket.renegotiate({ rejectUnauthorized: true }, (err) => {
if (err) console.error(err.code); // ERR_TLS_RENEGOTIATION_FAILED
});
}); // this triggers ERR_TLS_RENEGOTIATION_FAILEDtry {
// operation that may throw ERR_TLS_RENEGOTIATION_FAILED
riskyOperation()
} catch (err) {
if (err.code === 'ERR_TLS_RENEGOTIATION_FAILED') {
console.error('ERR_TLS_RENEGOTIATION_FAILED:', err.message)
} else {
throw err
}
}// Validate inputs before calling the operation
function safe_err_tls_renegotiation_failed(...args) {
// validate args here
return performOperation(...args)
}✕ Ignore renegotiation errors and continue using the socket
A failed renegotiation may leave the session in an undefined security state.
Node.js Error Codes Documentation
Content generated with AI assistance and reviewed for accuracy. Found an error? hello@errcodes.dev