Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tidy: clean up code for env loader #9642

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft

tidy: clean up code for env loader #9642

wants to merge 12 commits into from

Conversation

paperdave
Copy link
Collaborator

@paperdave paperdave commented Mar 26, 2024

What does this PR do?

Fixes #9635
Fixes #9445
Supercedes #9448

When we moved from std.process to our own spawn implementation, we moved from stdEnvMap to createNullDelimitedEnvMap in many places. i would like to highlight one line of the former:

        while (iter.next()) |entry| {
+           // Allow var from .env.development or .env.production to be loaded again
+           if (!entry.value_ptr.conditional) {
                try env_map.hash_map.put(entry.key_ptr.*, entry.value_ptr.value);
            }
        }

Such check is not present in createNullDelimitedEnvMap. We started passing a bunch of .conditional = true variables to subprocesses.

This PR removes .conditional and changes HashTableValue into just string. then, instead of loading variables that never get passed to subprocess, let's just not load them. the code reads much nicer.

After adding this check, it works, however this .conditional = true flag does not make any sense to me. I detail some more about this issue in this comment which is worth reading to get an understanding of the broken behavior this fixes.

As for createNullDelimitedEnvMap, when i made the change, i also turned the entire operation into a single allocation, instead of many smaller ones. This will make the memory easier to free (it is still a memory leak... maybe i fix)


I verify this code works by having many new tests, all of which i verify work on Bun 1.0.33, a commit before the regression.

Copy link

github-actions bot commented Mar 26, 2024

Copy link

github-actions bot commented Mar 26, 2024

Copy link

github-actions bot commented Mar 26, 2024

❌🪟 @paperdave, there are 10 test regressions on Windows x86_64

  • test\cli\install\bun-run-bunfig.test.ts
  • test\cli\install\bunx.test.ts
  • test\cli\run\env.test.ts
  • test\cli\test\bun-test.test.ts
  • test\cli\install\registry\bun-install-registry.test.ts
  • test\js\bun\console\console-iterator.test.ts
  • test\js\node\dns\node-dns.test.js
  • test\js\node\stream\node-stream.test.js
  • test\js\web\fetch\body-stream.test.ts
  • test\js\third_party\postgres\postgres.test.ts

Full Test Output

@paperdave paperdave changed the title fix(run): do not forward env file ("conditional") variables in createNullDelimitedEnvMap fix(run): do not load env files in the script runner Mar 26, 2024
this structure had a single field in it
src/env_loader.zig Outdated Show resolved Hide resolved
src/env_loader.zig Outdated Show resolved Hide resolved
@Jarred-Sumner
Copy link
Collaborator

Nice

@@ -391,18 +391,19 @@ pub const LifecycleScriptSubprocess = struct {
this.stderr.deinit();
}

this.env.deinit(this.manager.allocator);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice

@paperdave paperdave changed the title fix(run): do not load env files in the script runner tidy: clean up code for env loader Mar 29, 2024
@jdalton
Copy link
Contributor

jdalton commented Mar 29, 2024

@paperdave I'm glad you caught this. I'm wary of our policy of recreating the wheel of APIs that exist in the platform in part because of things like this that fall through the cracks. I'd rather contribute to fixing the lower level APIs where possible and deviating from them only when reaaally needed.

@paperdave paperdave marked this pull request as draft March 29, 2024 23:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
4 participants