From 4e1c20070204380df976741ba5fdb488471700f7 Mon Sep 17 00:00:00 2001 From: Joyee Cheung Date: Wed, 10 Aug 2022 02:01:02 +0800 Subject: [PATCH] bootstrap: check more metadata when loading the snapshot This patch stores the metadata about the Node.js binary into the SnapshotData and adds fields denoting how the snapshot was generated, on what platform it was generated as well as the V8 cached data version flag. Instead of simply crashing when the metadata doesn't match, Node.js now prints an error message and exit with 1 for the customized snapshot, or ignore the snapshot and start from scratch if it's the default one. PR-URL: https://github.com/nodejs/node/pull/44132 Reviewed-By: Anna Henningsen Reviewed-By: Chengzhong Wu --- doc/api/cli.md | 9 ++ src/env.cc | 15 +++ src/env.h | 20 ++- src/node.cc | 14 +- src/node_internals.h | 1 + src/node_snapshotable.cc | 142 ++++++++++++++++++-- test/parallel/test-snapshot-incompatible.js | 76 +++++++++++ 7 files changed, 260 insertions(+), 17 deletions(-) create mode 100644 test/parallel/test-snapshot-incompatible.js diff --git a/doc/api/cli.md b/doc/api/cli.md index 16bf8bcfb5cd37..bf6e435492943d 100644 --- a/doc/api/cli.md +++ b/doc/api/cli.md @@ -1185,6 +1185,15 @@ in the current working directory. When used without `--build-snapshot`, `--snapshot-blob` specifies the path to the blob that will be used to restore the application state. +When loading a snapshot, Node.js checks that: + +1. The version, architecture and platform of the running Node.js binary + are exactly the same as that of the binary that generates the snapshot. +2. The V8 flags and CPU features are compatible with that of the binary + that generates the snapshot. + +If they don't match, Node.js would refuse to load the snapshot and exit with 1. + ### `--test`