Skip to content

Commit 3f0c2e4

Browse files
authored
Revert "sea: mount vfsArchive at layer 0 and in workers"
This reverts commit ac9d85c. PR-URL: #66706 Fixes: #66703 Reviewed-By: Richard Lau <richard.lau@ibm.com> Reviewed-By: Stewart X Addison <sxa@redhat.com> Reviewed-By: Filip Skokan <panva.ip@gmail.com> Reviewed-By: Chengzhong Wu <legendecas@gmail.com>
1 parent 02bae37 commit 3f0c2e4

14 files changed

Lines changed: 22 additions & 193 deletions

‎doc/api/cli.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3946,10 +3946,6 @@ from anywhere else, such as the real file system, needs nothing added.
39463946
the command line's decision, and the environment must not be able to redirect
39473947
it.
39483948

3949-
A [single executable application][] built with `"vfsArchive"` mounts that
3950-
archive at the mount point reserved for `--vfs-load`, so `--vfs-load` cannot be
3951-
used in it.
3952-
39533949
```console
39543950
$ node --experimental-vfs --vfs-load=app.zip
39553951
```

‎doc/api/single-executable-applications.md‎

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -296,27 +296,6 @@ executable only embeds the archive; read the files through the file system
296296
APIs instead. `"vfsArchive"` requires `"useVfs": true` and cannot be
297297
combined with `"assets"`.
298298
299-
The archive is mounted at the mount point reserved for [`--vfs-load`][], which
300-
is the same in every thread, and worker threads mount it as well. A path into
301-
the archive, such as the main script's `__filename`, can therefore be loaded
302-
in a worker:
303-
304-
```cjs
305-
const { Worker, isMainThread } = require('node:worker_threads');
306-
307-
if (isMainThread) {
308-
new Worker(__filename);
309-
} else {
310-
// The worker runs the same script, from the same archive.
311-
console.log(require('./lib/math.js').add(2, 3));
312-
}
313-
```
314-
315-
Since that mount point is taken by the archive, `--vfs-load` cannot be used
316-
with `"vfsArchive"`: `--build-sea` rejects it in `"execArgv"`, and the
317-
executable rejects it at startup when it comes from `--node-options` or from
318-
the `execArgv` of a worker.
319-
320299
#### Snapshot and code caching limitations
321300
322301
`"useVfs": true` cannot be used together with `"useSnapshot": true` or
@@ -807,7 +786,6 @@ to help us document them.
807786
[Using native addons in the injected main script]: #using-native-addons-in-the-injected-main-script
808787
[VFS documentation]: vfs.md
809788
[Windows SDK]: https://developer.microsoft.com/en-us/windows/downloads/windows-sdk/
810-
[`--vfs-load`]: cli.md#--vfs-loadsource
811789
[`node:zlib`]: zlib.md
812790
[`process.execPath`]: process.md#processexecpath
813791
[`require()`]: modules.md#requireid

‎doc/api/vfs.md‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ const fs = require('node:fs');
223223
const myVfs = vfs.create();
224224
myVfs.writeFileSync('/data.txt', 'Hello');
225225
const mountPoint = myVfs.mount();
226-
// e.g. '/dev/null/vfs/1'
226+
// e.g. '/dev/null/vfs/0'
227227

228228
fs.readFileSync(`${mountPoint}/data.txt`, 'utf8'); // 'Hello'
229229
```

‎doc/node.1‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2012,9 +2012,6 @@ from anywhere else, such as the real file system, needs nothing added.
20122012
\fB--vfs-load\fR is not permitted in \fBNODE_OPTIONS\fR: which entry point runs is
20132013
the command line's decision, and the environment must not be able to redirect
20142014
it.
2015-
A single executable application built with \fB"vfsArchive"\fR mounts that
2016-
archive at the mount point reserved for \fB--vfs-load\fR, so \fB--vfs-load\fR cannot be
2017-
used in it.
20182015
.Bd -literal
20192016
$ node --experimental-vfs --vfs-load=app.zip
20202017
.Ed

‎lib/internal/main/embedding.js‎

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ const {
1616
isExperimentalSeaWarningNeeded,
1717
isSea,
1818
isVfsEnabled,
19+
mainCodePath: seaMainCodePath,
1920
} = internalBinding('sea');
2021
const { emitExperimentalWarning } = require('internal/util');
2122
const { emitWarningSync } = require('internal/process/warning');
@@ -133,12 +134,13 @@ function embedderRunESM(content, filename) {
133134
* @returns {string|null} The VFS path of the main script
134135
*/
135136
function setUpSeaVfs(content) {
136-
const { initSeaVfs, getSeaMainName } = require('internal/vfs/sea');
137-
const seaVfs = initSeaVfs(content);
137+
const mainName = path.basename(seaMainCodePath || process.execPath);
138+
const { initSeaVfs } = require('internal/vfs/sea');
139+
const seaVfs = initSeaVfs({ extraFiles: { [mainName]: content } });
138140
if (seaVfs === null) {
139141
return null;
140142
}
141-
return path.join(seaVfs.mountPoint, getSeaMainName());
143+
return path.join(seaVfs.mountPoint, mainName);
142144
}
143145
/* c8 ignore stop */
144146

‎lib/internal/main/worker_thread.js‎

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -152,9 +152,6 @@ port.on('message', (message) => {
152152
if (getOptionValue('--import').length === 0) {
153153
finishVfsMounts();
154154
}
155-
// Unlike the --vfs-load source, a SEA archive needs no provider that a
156-
// preload could register, so its mount is never deferred.
157-
require('internal/vfs/sea').initSeaVfsInWorker();
158155
}
159156

160157
if (!hasStdin)

‎lib/internal/vfs/sea.js‎

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,8 @@ const {
99
isVfsEnabled,
1010
isVfsArchiveEnabled,
1111
getAsset,
12-
getMainCode,
13-
mainCodePath,
1412
} = internalBinding('sea');
13+
const { kEmptyObject } = require('internal/util');
1514
const {
1615
codes: {
1716
ERR_INVALID_STATE,
@@ -30,12 +29,14 @@ let initialized = false;
3029
* SEA main script is placed at the mount point root so bundled code can
3130
* reach the assets through `__dirname`-relative paths and relative
3231
* `require()` calls.
33-
* @param {string|Buffer} mainCode The source of the SEA main script
32+
* @param {object} [options] Configuration options
33+
* @param {Record<string, string|Buffer>} [options.extraFiles] Additional
34+
* files to serve alongside the assets (used for the SEA main script)
3435
* @returns {VirtualFileSystem|null} The mounted VFS, or null if not running
3536
* as a SEA or VFS is not enabled in the SEA configuration
3637
* @throws {ERR_INVALID_STATE} If already initialized
3738
*/
38-
function initSeaVfs(mainCode) {
39+
function initSeaVfs(options = kEmptyObject) {
3940
if (initialized) {
4041
throw new ERR_INVALID_STATE('SEA VFS is already initialized');
4142
}
@@ -45,51 +46,25 @@ function initSeaVfs(mainCode) {
4546
return null;
4647
}
4748

48-
const { VirtualFileSystem, kLoadLayer } = require('internal/vfs/file_system');
49+
const { VirtualFileSystem } = require('internal/vfs/file_system');
4950

50-
const extraFiles = { __proto__: null, [getSeaMainName()]: mainCode };
51-
const isArchive = isVfsArchiveEnabled();
5251
let provider;
53-
if (isArchive) {
54-
provider = createZipProvider(extraFiles);
52+
if (isVfsArchiveEnabled()) {
53+
provider = createZipProvider(options.extraFiles);
5554
} else {
5655
const { SEAProvider } = require('internal/vfs/providers/sea');
57-
provider = new SEAProvider({ extraFiles });
56+
provider = new SEAProvider({ extraFiles: options.extraFiles });
5857
}
5958
// The SEA warning already covers the feature; don't emit the
6059
// VirtualFileSystem experimental warning for the implicit SEA mount.
61-
// An archive is mounted where --vfs-load mounts its source, which is the
62-
// same mount point in every thread, so a worker can reach the code in it.
6360
const vfs = new VirtualFileSystem(provider, {
64-
__proto__: null,
6561
emitExperimentalWarning: false,
66-
[kLoadLayer]: isArchive,
6762
});
6863
vfs.mount();
6964

7065
return vfs;
7166
}
7267

73-
/**
74-
* Mounts the SEA virtual file system in a worker, when it is backed by a
75-
* `"vfsArchive"`, so that a path into the mount in the main thread, such as
76-
* the main script's `__filename`, is also valid in the worker.
77-
*/
78-
function initSeaVfsInWorker() {
79-
if (isVfsArchiveEnabled()) {
80-
initSeaVfs(getMainCode());
81-
}
82-
}
83-
84-
/**
85-
* The name under which the SEA main script is placed at the mount point root.
86-
* @returns {string}
87-
*/
88-
function getSeaMainName() {
89-
const { basename } = require('path');
90-
return basename(mainCodePath || process.execPath);
91-
}
92-
9368
// The reserved asset key under which --build-sea stores the ZIP archive
9469
// named by "vfsArchive". Must match kVfsArchiveAssetName in src/node_sea.cc.
9570
const kVfsArchiveAssetName = 'node:sea:vfs.zip';
@@ -130,7 +105,5 @@ function createZipProvider(extraFiles) {
130105
/* c8 ignore stop */
131106

132107
module.exports = {
133-
getSeaMainName,
134108
initSeaVfs,
135-
initSeaVfsInWorker,
136109
};

‎src/node_options.cc‎

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -316,16 +316,6 @@ void EnvironmentOptions::CheckOptions(std::vector<std::string>* errors,
316316
errors->push_back("either --check or --eval can be used, not both");
317317
}
318318

319-
#ifndef DISABLE_SINGLE_EXECUTABLE_APPLICATION
320-
// The archive takes the mount point reserved for the --vfs-load source.
321-
if (!vfs_load_source.empty() && sea::IsSingleExecutable() &&
322-
sea::FindSingleExecutableResource().use_vfs_archive()) {
323-
errors->push_back(
324-
"--vfs-load cannot be used in a single executable application "
325-
"built with \"vfsArchive\"");
326-
}
327-
#endif // DISABLE_SINGLE_EXECUTABLE_APPLICATION
328-
329319
for (const std::string& pattern : permission::ParseEnvAllowList(allow_env)) {
330320
if (!permission::IsValidEnvAllowPattern(pattern)) {
331321
errors->push_back("--allow-env must be '*', a variable name, or a "

‎src/node_sea.cc‎

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -250,10 +250,6 @@ bool SeaResource::use_code_cache() const {
250250
return static_cast<bool>(flags & SeaFlags::kUseCodeCache);
251251
}
252252

253-
bool SeaResource::use_vfs_archive() const {
254-
return static_cast<bool>(flags & SeaFlags::kVfsArchive);
255-
}
256-
257253
const SeaResource& FindSingleExecutableResource() {
258254
static const SeaResource sea_resource = []() -> SeaResource {
259255
std::string_view blob = FindSingleExecutableBlob();
@@ -281,8 +277,12 @@ void IsVfsEnabled(const FunctionCallbackInfo<Value>& args) {
281277
}
282278

283279
void IsVfsArchiveEnabled(const FunctionCallbackInfo<Value>& args) {
284-
args.GetReturnValue().Set(IsSingleExecutable() &&
285-
FindSingleExecutableResource().use_vfs_archive());
280+
bool enabled = false;
281+
if (IsSingleExecutable()) {
282+
const SeaResource& sea_resource = FindSingleExecutableResource();
283+
enabled = static_cast<bool>(sea_resource.flags & SeaFlags::kVfsArchive);
284+
}
285+
args.GetReturnValue().Set(enabled);
286286
}
287287

288288
void IsExperimentalSeaWarningNeeded(const FunctionCallbackInfo<Value>& args) {
@@ -636,15 +636,6 @@ std::optional<SeaConfig> ParseSingleExecutableConfig(
636636
config_path);
637637
return std::nullopt;
638638
}
639-
// The archive takes the mount point reserved for the --vfs-load source.
640-
for (const std::string& arg : result.exec_argv) {
641-
if (arg == "--vfs-load" || arg.starts_with("--vfs-load=")) {
642-
FPrintF(stderr,
643-
"\"vfsArchive\" cannot be used together with --vfs-load in "
644-
"\"execArgv\"\n");
645-
return std::nullopt;
646-
}
647-
}
648639
// The archive is embedded as a single reserved asset.
649640
result.flags |= SeaFlags::kIncludeAssets;
650641
}
@@ -975,20 +966,6 @@ void GetAssetKeys(const FunctionCallbackInfo<Value>& args) {
975966
args.GetReturnValue().Set(result);
976967
}
977968

978-
// A worker has no main script handed to it, but places the SEA main script in
979-
// its virtual file system just as the main thread does.
980-
void GetMainCode(const FunctionCallbackInfo<Value>& args) {
981-
CHECK_EQ(args.Length(), 0);
982-
const SeaResource& sea_resource = FindSingleExecutableResource();
983-
CHECK(!sea_resource.use_snapshot());
984-
Local<Value> code;
985-
if (ToV8Value(args.GetIsolate()->GetCurrentContext(),
986-
sea_resource.main_code_or_snapshot)
987-
.ToLocal(&code)) {
988-
args.GetReturnValue().Set(code);
989-
}
990-
}
991-
992969
MaybeLocal<Value> LoadSingleExecutableApplication(
993970
const StartExecutionCallbackInfoWithModule& info) {
994971
// Here we are currently relying on the fact that in NodeMainInstance::Run(),
@@ -1071,7 +1048,6 @@ void Initialize(Local<Object> target,
10711048
IsExperimentalSeaWarningNeeded);
10721049
SetMethod(context, target, "getAsset", GetAsset);
10731050
SetMethod(context, target, "getAssetKeys", GetAssetKeys);
1074-
SetMethod(context, target, "getMainCode", GetMainCode);
10751051
}
10761052

10771053
void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
@@ -1081,7 +1057,6 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
10811057
registry->Register(IsExperimentalSeaWarningNeeded);
10821058
registry->Register(GetAsset);
10831059
registry->Register(GetAssetKeys);
1084-
registry->Register(GetMainCode);
10851060
}
10861061

10871062
} // namespace sea

‎src/node_sea.h‎

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ struct SeaResource {
6464

6565
bool use_snapshot() const;
6666
bool use_code_cache() const;
67-
bool use_vfs_archive() const;
6867

6968
static constexpr size_t kHeaderSize = sizeof(kMagic) + sizeof(SeaFlags) +
7069
sizeof(SeaExecArgvExtension) +

0 commit comments

Comments
 (0)