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

Fix #2881 Propagate environment from ctx to subprocesses #2882

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

Conversation

lolgab
Copy link
Member

@lolgab lolgab commented Nov 18, 2023

Fixes #2881

Dependencies

Comment on lines 233 to 234
stderr = backgroundOutputs.map(_._2).getOrElse(os.Pipe),
propagateEnv = false
Copy link
Member

Choose a reason for hiding this comment

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

I'm not convinced this is correct. Yes, in order to avoid using stale env vars from the server, we need to set propagaEnv to false. But I think we should then always use the env vars send to us from the client as a base line. And if some env vars are given by the parameters, we should add them too.

This logic is of course not easily applyable here, as we don't have the access to the target context here.

Copy link
Member

Choose a reason for hiding this comment

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

The test case should use a env var typically used by the OS which is now unset.

Copy link
Member Author

Choose a reason for hiding this comment

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

I did not know that envArgs are meant to be additional environment variables and not all the environment to be passed to the process.
I'm not sure how to achieve this to be honest..
We could add a propagateEnv: Boolean = true parameter here and set it to false when we know that we don't want to propagate the environment.
We could also add a private global AtomicReference holding the current env and set it when we read the environment from client and read it here.
Do you have other ideas?

Copy link
Member

Choose a reason for hiding this comment

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

TBH, we never specified whether a run with an empty forkEnv should use the OS env or the empty env. But the status quo seems to exactly do this. But in run we have access to a task context, so we could also accept an implicit one in the Jvm API.

Without passing it explicitly/implicitly, holding a static (global) map might be the alternative.

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH, we never specified whether a run with an empty forkEnv should use the OS env or the empty env. But the status quo seems to exactly do this. But in run we have access to a task context, so we could also accept an implicit one in the Jvm API.

We could change this but, in case, I would prefer to do it in Mill 0.12 breaking window.

Without passing it explicitly/implicitly, holding a static (global) map might be the alternative.

This seems the easiest solution as it doesn't need to introduce new APIs / deprecate APIs. Also, the environment is stable enough since you can't change it at runtime on the JVM. So the variable would change not that often (at most once per CLI execution).

Copy link
Member Author

Choose a reason for hiding this comment

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

I ended up adding some private methods that receive also the propagateEnv argument so we can pass the env we have already in an implicit ctx: Ctx in Jvm. I don't want to make these overloads public since in 0.12 it's better to add (implicit ctx: Ctx) to the methods instead.

the current semantics of runSubprocess methods are that the env
arguments are not the whole env but extra arguments passed added to the
system environment.
To allow passing the client env we need to use ctx.
We can't add overloads with an implicit parameter list
so I'm adding private overloads that recieve a `propagateEnv: Boolean`
parameter to be passed to os-lib.
This API is not what we want and will be revisited in Mill 0.12, that's
why I made the new methods private.
@lolgab
Copy link
Member Author

lolgab commented Nov 18, 2023

Now I don't have idea how to test this. Do we have integration tests where the client is used to call run on a module?

@lolgab lolgab changed the title Fix #2881 Avoid propagating server environment Fix #2881 Propagate environment from ctx to subprocesses Nov 18, 2023
@lolgab lolgab added the compat-breaker This PR is good to merge, but breaks compatibility and needs to wait till we prepare a major release label Jun 17, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
compat-breaker This PR is good to merge, but breaks compatibility and needs to wait till we prepare a major release
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Stale server environment is propagated when running processes with run
2 participants