Skip to content

Conversation

@goutamvenkat-anyscale
Copy link
Contributor

@goutamvenkat-anyscale goutamvenkat-anyscale commented Oct 3, 2025

Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target (file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to be flushed, so they're retained in memory, hence it accumulates to no end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like level, target, filter and formatters) and restore them after calling dictConfig()

Based off of https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c (Ray Core - Ray Data log fix)

Related issue number

Checks

  • I've signed off every commit(by using the -s flag, i.e., git commit -s) in this PR.
  • I've run pre-commit jobs to lint the changes in this PR. (pre-commit setup)
  • I've included any doc changes needed for https://docs.ray.io/en/master/.
    • I've added any new APIs to the API Reference. For example, if I added a
      method in Tune, I've added it in doc/source/tune/api/ under the
      corresponding .rst file.
  • I've made sure the tests are passing. Note that there might be a few flaky tests, see the recent failures at https://flakey-tests.ray.io/
  • Testing Strategy
    • Unit tests
    • Release tests
    • This PR is not tested :(

Signed-off-by: Goutam V. <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale requested a review from a team as a code owner October 3, 2025 21:06
@goutamvenkat-anyscale goutamvenkat-anyscale added the data Ray Data-related issues label Oct 3, 2025
cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request effectively addresses the issue of configuring logging at module import time by deferring it until a ray.data operation is active. The use of a thread-safe, double-checked locking pattern in configure_logging ensures that initialization is performed lazily and idempotently, which is a robust approach. The changes correctly remove the eager configuration from ray/data/__init__.py and introduce the lazy call in register_dataset_logger. I have one suggestion to further improve the implementation by moving environment variable access out of the critical section to minimize lock contention.

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam V. <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale added the go add ONLY when ready to merge, run all tests label Oct 3, 2025
cursor[bot]

This comment was marked as outdated.

cursor[bot]

This comment was marked as outdated.

Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale changed the title [Data] - Don't configure logging at module import [Data] - Preserve existing handlers for logging Oct 9, 2025
Signed-off-by: Goutam <goutam@anyscale.com>
@goutamvenkat-anyscale
Copy link
Contributor Author

/gemini review

cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

This pull request addresses a critical issue where log handlers were being closed during reconfiguration, potentially causing log messages to be lost. The solution of saving and restoring handler states is a good approach. My main feedback is that the current implementation overlooks the root logger, which could still be affected by the original issue. I've added a specific comment with a suggestion to include the root logger in the preservation logic.

Signed-off-by: Goutam <goutam@anyscale.com>
cursor[bot]

This comment was marked as outdated.

Signed-off-by: Goutam <goutam@anyscale.com>
cursor[bot]

This comment was marked as outdated.

Signed-off-by: Goutam <goutam@anyscale.com>
cursor[bot]

This comment was marked as outdated.

Copy link
Contributor

@omatthew98 omatthew98 left a comment

Choose a reason for hiding this comment

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

Some of the code is a little unintuitive so maybe try to capture some more info in comments, but overall lgtm.

Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
cursor[bot]

This comment was marked as outdated.

Signed-off-by: Goutam <goutam@anyscale.com>
cursor[bot]

This comment was marked as outdated.

Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
@goutamvenkat-anyscale goutamvenkat-anyscale changed the title [Data] - Preserve existing handlers for logging [Data] - Preserve existing handlers for logging - don't use dictConfig Oct 16, 2025
cursor[bot]

This comment was marked as outdated.

Signed-off-by: Goutam <goutam@anyscale.com>
cursor[bot]

This comment was marked as outdated.

Comment on lines 190 to 192
logger = logging.getLogger(logger_name)
if not logger.handlers:
loggers_to_configure[logger_name] = logger_config
Copy link
Contributor

Choose a reason for hiding this comment

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

Please add a comment to explain how there could be a logger w/ no handlers

@alexeykudinkin alexeykudinkin enabled auto-merge (squash) October 16, 2025 22:55
@github-actions github-actions bot disabled auto-merge October 17, 2025 04:27
@alexeykudinkin alexeykudinkin merged commit f9c009a into ray-project:master Oct 17, 2025
6 checks passed
@goutamvenkat-anyscale goutamvenkat-anyscale deleted the goutam/fix_rd_logging branch October 17, 2025 19:02
justinyeh1995 pushed a commit to justinyeh1995/ray that referenced this pull request Oct 20, 2025
…ig` (ray-project#57169)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target
(file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler
is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to
be flushed, so they're retained in memory, hence it accumulates to no
end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like
`level`, `target`, `filter` and `formatters`) and restore them after
calling `dictConfig()`

Based off of
https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c
(Ray Core - Ray Data log fix)


## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run pre-commit jobs to lint the changes in this PR.
([pre-commit
setup](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#lint-and-formatting))
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
xinyuangui2 pushed a commit to xinyuangui2/ray that referenced this pull request Oct 22, 2025
…ig` (ray-project#57169)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target
(file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler
is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to
be flushed, so they're retained in memory, hence it accumulates to no
end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like
`level`, `target`, `filter` and `formatters`) and restore them after
calling `dictConfig()`

Based off of
https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c
(Ray Core - Ray Data log fix)

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run pre-commit jobs to lint the changes in this PR.
([pre-commit
setup](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#lint-and-formatting))
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: xgui <xgui@anyscale.com>
elliot-barn pushed a commit that referenced this pull request Oct 23, 2025
…ig` (#57169)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target
(file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler
is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to
be flushed, so they're retained in memory, hence it accumulates to no
end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like
`level`, `target`, `filter` and `formatters`) and restore them after
calling `dictConfig()`

Based off of
https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c
(Ray Core - Ray Data log fix)


## Related issue number

<!-- For example: "Closes #1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run pre-commit jobs to lint the changes in this PR.
([pre-commit
setup](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#lint-and-formatting))
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: elliot-barn <elliot.barnwell@anyscale.com>
landscapepainter pushed a commit to landscapepainter/ray that referenced this pull request Nov 17, 2025
…ig` (ray-project#57169)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target
(file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler
is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to
be flushed, so they're retained in memory, hence it accumulates to no
end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like
`level`, `target`, `filter` and `formatters`) and restore them after
calling `dictConfig()`

Based off of
https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c
(Ray Core - Ray Data log fix)


## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run pre-commit jobs to lint the changes in this PR.
([pre-commit
setup](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#lint-and-formatting))
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Aydin-ab pushed a commit to Aydin-ab/ray-aydin that referenced this pull request Nov 19, 2025
…ig` (ray-project#57169)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target
(file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler
is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to
be flushed, so they're retained in memory, hence it accumulates to no
end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like
`level`, `target`, `filter` and `formatters`) and restore them after
calling `dictConfig()`

Based off of
https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c
(Ray Core - Ray Data log fix)

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run pre-commit jobs to lint the changes in this PR.
([pre-commit
setup](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#lint-and-formatting))
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Aydin Abiar <aydin@anyscale.com>
Future-Outlier pushed a commit to Future-Outlier/ray that referenced this pull request Dec 7, 2025
…ig` (ray-project#57169)

<!-- Thank you for your contribution! Please review
https://github.com/ray-project/ray/blob/master/CONTRIBUTING.rst before
opening a pull request. -->

<!-- Please add a reviewer to the assignee section when you create a PR.
If you don't have the access to it, we will shortly find a reviewer and
assign them to your PR. -->

## Why are these changes needed?

So the way the logger works is log() -> buffer -> flush() -> target
(file/console/remote_uri)
On shutdown (triggered by logging.config.dictConfig), the MemoryHandler
is closed which sets the output target to None
When the target is set to None, the logs in the buffer have nowhere to
be flushed, so they're retained in memory, hence it accumulates to no
end.

Solution:
Temporarily detach the handlers for loggers (preserve attributes like
`level`, `target`, `filter` and `formatters`) and restore them after
calling `dictConfig()`

Based off of
https://github.com/ray-project/ray/pull/48958/files#diff-d5e32f872cf7b123f0899714728ac7fc0916a5609844a7d1bf7317d98094778c
(Ray Core - Ray Data log fix)

## Related issue number

<!-- For example: "Closes ray-project#1234" -->

## Checks

- [x] I've signed off every commit(by using the -s flag, i.e., `git
commit -s`) in this PR.
- [x] I've run pre-commit jobs to lint the changes in this PR.
([pre-commit
setup](https://docs.ray.io/en/latest/ray-contribute/getting-involved.html#lint-and-formatting))
- [ ] I've included any doc changes needed for
https://docs.ray.io/en/master/.
- [ ] I've added any new APIs to the API Reference. For example, if I
added a
method in Tune, I've added it in `doc/source/tune/api/` under the
           corresponding `.rst` file.
- [ ] I've made sure the tests are passing. Note that there might be a
few flaky tests, see the recent failures at https://flakey-tests.ray.io/
- Testing Strategy
   - [x] Unit tests
   - [ ] Release tests
   - [ ] This PR is not tested :(

---------

Signed-off-by: Goutam V. <goutam@anyscale.com>
Signed-off-by: Goutam <goutam@anyscale.com>
Signed-off-by: Future-Outlier <eric901201@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

data Ray Data-related issues 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