Skip to content

[go1.20] internal/godebug env watcher update #1313

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

Merged
merged 1 commit into from
Jun 4, 2024

Conversation

grantnelson-wf
Copy link
Collaborator

In internal/godebug the setUpdate method is used to watch for changes to the environment variable GODEBUG. This is used by tests such as the archive/zip test TestInsecurePaths or any test using t.Setenv.

To solve this I added a way to inject a JS Proxy into process.env that calls a callback when any environment variable is set, the callback will handle the rest of the update and call the function provided to setUpdate.

Testing this was a little hard since godebug is used by tests. I solved this by creating a go:link from a test that is external to godebug.

This is part of #1270

Copy link
Member

@nevkontakte nevkontakte left a comment

Choose a reason for hiding this comment

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

I'd like to avoid modifying the global environment, since it creates a risk of conflicting with some other library, even if the chance of that happening in stdlib tests is slim.

Since we are already overriding Setenv/Getenv implementations, can we implement the hook at Go level instead?

@grantnelson-wf
Copy link
Collaborator Author

That makes sense. I was trying to make the injection such that any other proxy could also inject on top or below it, but it is worrying that it is modifying process.env. I'll see if I can implement this inside of syscall/syscall_js_wasm.go with the runtimeSetenv/runtimeUnsetenv methods using just go.

It does appear that anytime this callback is being used is being done via testing SetEnv and not something else like command to set environment variables some other way, so having a more broad watcher shouldn't be needed.

I'll rework it.

@nevkontakte
Copy link
Member

Yeah, I can also imagine runtimes that doesn't allow reassigning process.env, or some code trying to use reflection on it and having issues as a result.

@nevkontakte nevkontakte merged commit 2dd555b into gopherjs:go1.20 Jun 4, 2024
5 of 8 checks passed
@grantnelson-wf grantnelson-wf deleted the godebugUpdate branch June 4, 2024 20:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants