From 08428bebf48c19228d6fc2f1a0174b8575535ba9 Mon Sep 17 00:00:00 2001 From: Filip Skokan Date: Wed, 21 Oct 2026 09:33:12 +0200 Subject: [PATCH] test: handle stringbytes allocation failures MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Buffer.allocUnsafe() can throw ERR_MEMORY_ALLOCATION_FAILED under memory pressure. Accept it alongside the V8 allocation-failure message so the tests take their intended low-memory skip. Signed-off-by: Filip Skokan Assisted-by: Codex PR-URL: https://github.com/nodejs/node/pull/66887 Reviewed-By: Richard Lau Reviewed-By: Luigi Pinca Reviewed-By: Gürgün Dayıoğlu --- .../test-stringbytes-external-at-max.js | 3 ++- .../test-stringbytes-external-exceed-max-by-1-ascii.js | 3 ++- .../test-stringbytes-external-exceed-max-by-1-base64.js | 3 ++- .../test-stringbytes-external-exceed-max-by-1-binary.js | 3 ++- .../test-stringbytes-external-exceed-max-by-1-hex.js | 3 ++- .../test-stringbytes-external-exceed-max-by-1-utf8.js | 3 ++- .../test-stringbytes-external-exceed-max-by-2.js | 3 ++- .../test-stringbytes-external-exceed-max.js | 3 ++- 8 files changed, 16 insertions(+), 8 deletions(-) diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js index fcf5279dd3c..87a754cb216 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-at-max.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js index 6aff0445195..e03b5ae0352 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-ascii.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js index 7c8e2d92c6a..9ffff4fdbbe 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-base64.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js index 176c095e22e..c962c491d0c 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-binary.js @@ -18,7 +18,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js index a473e0e90fb..1cef739c5c3 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-hex.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js index 25271fad94b..2e00ff49722 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-1-utf8.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 1); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js index 121ca2d62ba..6fbc52849c4 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max-by-2.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength + 2); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); } diff --git a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js index b843be5a9ab..e13f865405c 100644 --- a/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js +++ b/test/addons/stringbytes-external-exceed-max/test-stringbytes-external-exceed-max.js @@ -17,7 +17,8 @@ try { buf = Buffer.allocUnsafe(kStringMaxLength * 2 + 2); } catch (e) { // If the exception is not due to memory confinement then rethrow it. - if (e.message !== 'Array buffer allocation failed') throw (e); + if (e.code !== 'ERR_MEMORY_ALLOCATION_FAILED' && + e.message !== 'Array buffer allocation failed') throw (e); common.skip(skipMessage); }