Skip to content

Commit 37d9dc7

Browse files
authored
fix(pacmak): invokeBinScript fails when using symlinked cache (#4389)
This was previously attempted to fix in #4324 While the above fix resolves issues with dependencies, it causes failures when the binary is shelling out to other node processes. This is due to the intrusive and indiscriminate overloading of NODE_OPTIONS, which will forcibly apply to any child processes as well. While in theory adding the symlink flags should not be an issue, this seems to trigger a bug in node: nodejs/node#41000 tl;dr this all sucks very much and we are now just disabling the runtime cache for binaries. --- By submitting this pull request, I confirm that my contribution is made under the terms of the [Apache 2.0 license]. [Apache 2.0 license]: https://www.apache.org/licenses/LICENSE-2.0
1 parent 456f417 commit 37d9dc7

File tree

5 files changed

+26
-10
lines changed

5 files changed

+26
-10
lines changed

gh-pages/content/overview/runtime-architecture.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
# Runtime Architecture
2+
23
## Generated Libraries
34

45
When using `jsii-pacmak` to generate libraries in different programming
@@ -149,7 +150,7 @@ The initialization workflow can be described as:
149150
the child's `STDERR` stream, and forwards the decoded data to it's host
150151
process' `STDERR` and `STDOUT` as needed.
151152
4. The *runtime client library* automatically loads the **Javascript** modules
152-
bundled within the *generated bindings* (and their depedencies, bundled in
153+
bundled within the *generated bindings* (and their dependencies, bundled in
153154
other *generated bindings*) into the `node` process when needed.
154155
5. Calls into the *Generated bindings* are encoded into JSON requests and sent
155156
to the child `node` process, which will execute the corresponding

packages/@jsii/kernel/src/kernel.ts

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,11 +1372,6 @@ export class Kernel {
13721372
// Make sure the current NODE_OPTIONS are honored if we shell out to node
13731373
const nodeOptions = [...process.execArgv];
13741374

1375-
// When we are using the symlinked version of the cache, we need to preserve both symlink settings for binaries
1376-
if (nodeOptions.includes('--preserve-symlinks')) {
1377-
nodeOptions.push('--preserve-symlinks-main');
1378-
}
1379-
13801375
return {
13811376
command: path.join(packageDir, scriptPath),
13821377
args: req.args ?? [],

packages/@jsii/python-runtime/tests/test_invoke_bin.py

Lines changed: 15 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,21 @@ def silence_node_deprecation_warnings():
3535
environ[var] = store[var]
3636

3737

38+
@pytest.fixture()
39+
def disable_jsii_runtime_package_cache():
40+
"""Disable the jsii runtime cache because it is problematic with InvokeBinScript."""
41+
42+
environ["JSII_RUNTIME_PACKAGE_CACHE"] = "disabled"
43+
44+
3845
class TestInvokeBinScript:
3946
@pytest.mark.skipif(
4047
platform.system() == "Windows",
4148
reason="jsii-pacmak does not generate windows scripts",
4249
)
43-
def test_invoke_script(self, silence_node_deprecation_warnings) -> None:
50+
def test_invoke_script(
51+
self, silence_node_deprecation_warnings, disable_jsii_runtime_package_cache
52+
) -> None:
4453
script_path = f".env/bin/calc"
4554
result = subprocess.run([script_path], capture_output=True)
4655

@@ -51,7 +60,9 @@ def test_invoke_script(self, silence_node_deprecation_warnings) -> None:
5160
platform.system() == "Windows",
5261
reason="jsii-pacmak does not generate windows scripts",
5362
)
54-
def test_invoke_script_with_args(self, silence_node_deprecation_warnings) -> None:
63+
def test_invoke_script_with_args(
64+
self, silence_node_deprecation_warnings, disable_jsii_runtime_package_cache
65+
) -> None:
5566
script_path = f".env/bin/calc"
5667
result = subprocess.run([script_path, "arg1", "arg2"], capture_output=True)
5768

@@ -63,7 +74,7 @@ def test_invoke_script_with_args(self, silence_node_deprecation_warnings) -> Non
6374
reason="jsii-pacmak does not generate windows scripts",
6475
)
6576
def test_invoke_script_with_failure(
66-
self, silence_node_deprecation_warnings
77+
self, silence_node_deprecation_warnings, disable_jsii_runtime_package_cache
6778
) -> None:
6879
script_path = f".env/bin/calc"
6980
result = subprocess.run([script_path, "arg1", "fail"], capture_output=True)
@@ -77,7 +88,7 @@ def test_invoke_script_with_failure(
7788
reason="jsii-pacmak does not generate windows scripts",
7889
)
7990
def test_invoke_script_with_line_flush(
80-
self, silence_node_deprecation_warnings
91+
self, silence_node_deprecation_warnings, disable_jsii_runtime_package_cache
8192
) -> None:
8293
"""Make sure lines are flushed immediately as they are generated, rather than
8394
buffered to the end

packages/jsii-pacmak/lib/targets/python.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1833,6 +1833,11 @@ class PythonModule implements PythonType {
18331833
code.line();
18341834
code.line('import jsii');
18351835
code.line('import sys');
1836+
code.line('import os');
1837+
code.line();
1838+
code.openBlock('if "JSII_RUNTIME_PACKAGE_CACHE" not in os.environ');
1839+
code.line('os.environ["JSII_RUNTIME_PACKAGE_CACHE"] = "disabled"');
1840+
code.closeBlock();
18361841
code.line();
18371842
emitList(
18381843
code,

packages/jsii-pacmak/test/generated-code/__snapshots__/target-python.test.js.snap

Lines changed: 4 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)