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

[core] Implement scoped env setter #50396

Merged
merged 2 commits into from
Feb 11, 2025
Merged

Conversation

dentiny
Copy link
Contributor

@dentiny dentiny commented Feb 10, 2025

When working on pipe logger (#50248), I found it necessary to test based on a scoped env, so make a formal util.

@dentiny dentiny added the go add ONLY when ready to merge, run all tests label Feb 10, 2025
@dentiny dentiny requested review from jjyao, edoakes and dayshah February 10, 2025 22:28
Signed-off-by: dentiny <[email protected]>
@jjyao
Copy link
Collaborator

jjyao commented Feb 10, 2025

@dayshah could you review?

@edoakes
Copy link
Contributor

edoakes commented Feb 10, 2025

@dentiny don't see it used anywhere -- are there tests you'd update to use this?

@dentiny
Copy link
Contributor Author

dentiny commented Feb 10, 2025

@dentiny don't see it used anywhere -- are there tests you'd update to use this?

It's used here:

class PipeReadBufferSizeSetter {
public:
PipeReadBufferSizeSetter(size_t pipe_buffer_size) {
setEnv(kPipeLogReadBufSizeEnv.data(), absl::StrFormat("%d", pipe_buffer_size).data());
}
~PipeReadBufferSizeSetter() { unsetEnv(kPipeLogReadBufSizeEnv.data()); }
};

The PR's still pending review, not merged yet

@dentiny dentiny closed this Feb 10, 2025
@dentiny dentiny reopened this Feb 10, 2025
Copy link
Contributor

@dayshah dayshah left a comment

Choose a reason for hiding this comment

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

lgtm but maybe overkill to have a utility if we only have one use case for it rn?

ScopedEnvSetter::~ScopedEnvSetter() {
unsetEnv(env_name_.c_str());
if (old_value_.has_value()) {
setEnv(env_name_, *old_value_);
Copy link
Contributor

Choose a reason for hiding this comment

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

idk how this will be used but are races with setenv a concern -https://en.cppreference.com/w/cpp/utility/program/getenv?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only expect to be useful in unit tests at the moment, not a big concern for thread-safety.
Speaking of which, strerror is also not thread-safe, might be a bigger concern.

src/ray/util/scoped_env_setter.h Show resolved Hide resolved
Signed-off-by: dentiny <[email protected]>
@dentiny
Copy link
Contributor Author

dentiny commented Feb 10, 2025

lgtm but maybe overkill to have a utility if we only have one use case for it rn?

I imagine it'd be useful in unit tests, no intended use cases other than that.

@jjyao jjyao merged commit 56e1ab9 into ray-project:master Feb 11, 2025
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
go add ONLY when ready to merge, run all tests
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants