Skip to content

fix: resolve infinite loop in _find_config on Windows systems #4970

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 8 commits into from
Mar 10, 2025

Conversation

Julfried
Copy link
Contributor

@Julfried Julfried commented Dec 17, 2024

Issue #4967

Description of changes:
This PR fixes an infinite loop in _find_config that occurs on Windows systems. The issue was caused by using Path.match("/") to detect root directories, which never matches on Windows due to different path separators.

Changes made:

  1. Replace platform-specific Path.match("/") with Path.anchor comparison
  2. Implement proper root directory detection for both Windows and Unix systems
  3. Add comprehensive cross-platform tests

Testing done:

  • Verified fix on both Windows and Linux systems
  • Added test_find_config_cross_platform to validate:
    • Basic path traversal
    • Nested directory structures
    • Root directory handling
    • Non-existent config scenarios
  • Added test_find_config_path_separators to verify handling of:
    • Forward slashes
    • Backslashes
    • Mixed separators
  • All existing tests pass without modification

Merge Checklist

General

  • I have read the CONTRIBUTING doc
  • I certify that the changes I am introducing will be backward compatible
  • I used the commit message format described in CONTRIBUTING
  • I have passed the region in to all S3 and STS clients (N/A for this change)
  • I have updated necessary documentation (N/A - internal implementation change)

Tests

  • I have added tests that prove my fix is effective
  • I have added unit tests to ensure backward compatibility
  • I have checked that my tests are not configured for a specific region or account
  • I have used unique_name_from_base for resource names (N/A - unit tests only)
  • No new dependencies added

By submitting this pull request, I confirm that my contribution is made under the terms of the Apache 2.0 license.

@Julfried Julfried requested a review from a team as a code owner December 17, 2024 16:08
@Julfried Julfried requested a review from nargokul December 17, 2024 16:08
@Julfried
Copy link
Contributor Author

Quick update: I was unsure about two checklist items and checked them with N/A, because I think they are not applicable for my changes:

  1. "Passed region to S3/STS clients"
  2. "Documentation updated"

Please let me know if there is anything I need to do, to get this merged. Thanks!

@ahmednmourad
Copy link

I have been struggling with this for days. Thank you!

@Julfried
Copy link
Contributor Author

Thanks, hopefully they merge this soon, because this bug is really confusing and frustrating. Especially for new users!

@Julfried
Copy link
Contributor Author

Hey @nargokul

Just following up on this PR! The fix resolves a frustrating infinite loop issue on Windows (#4967) caused by a root path detection method that only worked on Linux. It updates the logic to properly handle cross plattform paths.

Looks like the CI is stuck on the wait-for-approval step—would you mind approving it so the checks can run? Let me know if there’s anything else I should adjust.

Thanks!

@Julfried
Copy link
Contributor Author

Since this PR seems to be stale, I’d like to follow up to see if there’s anything else needed from my side to move it forward.

@benieric, @pintaoz-aws – Would you be able to take a look at this? I’ve recently rebased the branch to the latest master to ensure it’s up-to-date and ready for review.

This fix addresses a frustrating bug (#4967) that causes an infinite loop on Windows systems. Resolving this would greatly improve the developer experience, especially for new users facing this issue.

Please let me know if any further changes or additional information are needed. Thanks for your time and support!

@benieric
Copy link
Contributor

Hey sorry for the delay! Thanks for raising this fix and adding tests will look to get this merged ASAP

@benieric
Copy link
Contributor

benieric commented Jan 31, 2025

Aiming to get this included in next release if tests are passing, thanks!

benieric
benieric previously approved these changes Jan 31, 2025
@benieric
Copy link
Contributor

Can you run tox -e black-format to fix codestyle errors. We'll get this in the next release once tests passing

@Julfried
Copy link
Contributor Author

Julfried commented Feb 1, 2025

Hey @benieric,

No worries about the delay—I really appreciate your help! I’ve fixed the formatting style as requested.
Just glad to get this merged—let me know if anything else is needed! 🙂

@ejh-alexchatwin
Copy link

ejh-alexchatwin commented Feb 26, 2025

Hi Friends, if this can't be merged for some reason, is there at least a work around?

edit: the workaround is changing 4ish lines of code in one of the files to match this merge.. surely we can merge this?

@Julfried
Copy link
Contributor Author

Julfried commented Feb 27, 2025

I agree that this should be merged. As a temporary workaround you can add this to your requirements.txt file to install the fork where the fix is applied if you are on a windows machine:

git+https://github.com/Julfried/sagemaker-python-sdk.git ; sys_platform == "win32"
sagemaker >=2.228 ; sys_platform != "win32"

@benieric could you please approve so that the tests can run?

@ejh-alexchatwin
Copy link

Thanks - that's a much tidier workaround than my current hack 😅

@benieric benieric temporarily deployed to manual-approval March 4, 2025 00:31 — with GitHub Actions Inactive
@benieric
Copy link
Contributor

benieric commented Mar 4, 2025

Seems there are still some codestyles failing if you could take a look

@Julfried Julfried temporarily deployed to manual-approval March 4, 2025 07:29 — with GitHub Actions Inactive
@Julfried
Copy link
Contributor Author

Julfried commented Mar 4, 2025

Thanks, I fixed the line too long error, so hopefully it passes now. Unfortunately I am unable to run the tests locally using tox. But when running them with plain pytest they pass.

@Julfried Julfried temporarily deployed to manual-approval March 5, 2025 08:01 — with GitHub Actions Inactive
@mollyheamazon
Copy link
Contributor

Could you please take a look at the failed PR checks? Thanks!

Julfried and others added 4 commits March 6, 2025 09:34
@Julfried
Copy link
Contributor Author

Julfried commented Mar 6, 2025

Rebased to skip the deprecated instance type. Lets see if it works now

@Julfried Julfried temporarily deployed to manual-approval March 6, 2025 21:12 — with GitHub Actions Inactive
@Julfried
Copy link
Contributor Author

Julfried commented Mar 6, 2025

I am very sorry for all the failing runs. I fixed the broken test_case for non windows machines and verified that the tests are passing on WSL on my laptop. Hopefully this works now!

@ejh-alexchatwin
Copy link

Honestly I'm impressed you're still putting in effort to align with their rules given you're working to fix the existing nicely-formatted-but-broken code. thank you!

@Julfried
Copy link
Contributor Author

Julfried commented Mar 6, 2025

To be honest, I've already invested so much time and effort in troubleshooting in debugging this frustrating issue. So I thought, why not just push through to get it solved for everyone ;)

@mollyheamazon
Copy link
Contributor

@Julfried Thank you for your contribution and your dedication! Let's see if this issue is fixed by now.

@Julfried
Copy link
Contributor Author

Julfried commented Mar 10, 2025

Since all tests are passing, I think this can be merged now.

@benieric benieric merged commit 8a6ab21 into aws:master Mar 10, 2025
14 checks passed
@ejh-alexchatwin
Copy link

Thanks everyone, especially @Julfried, for resolving this very-hard-to-debug bug!

mollyheamazon pushed a commit to mollyheamazon/sagemaker-python-sdk that referenced this pull request Mar 14, 2025
* fix: resolve Windows path handling in _find_config

* Replace Path.match("/") with Path.anchor comparison
* Fix infinite loop in _studio.py path traversal

* test: Add tests for the new root path exploration

* Fix formatting style

* Fixed line to long

* Fix docstyle by running black manually

* Fix testcase with \\ when running on non-windows machines

* Fix formatting style

* cleanup unused import
evakravi pushed a commit to evakravi/sagemaker-python-sdk that referenced this pull request Mar 20, 2025
* fix: resolve Windows path handling in _find_config

* Replace Path.match("/") with Path.anchor comparison
* Fix infinite loop in _studio.py path traversal

* test: Add tests for the new root path exploration

* Fix formatting style

* Fixed line to long

* Fix docstyle by running black manually

* Fix testcase with \\ when running on non-windows machines

* Fix formatting style

* cleanup unused import
@achamma723
Copy link

achamma723 commented Mar 27, 2025

Hello, we have the same problem on Macos. Any ideas for a fix?

mollyheamazon pushed a commit to mollyheamazon/sagemaker-python-sdk that referenced this pull request Apr 8, 2025
* fix: resolve Windows path handling in _find_config

* Replace Path.match("/") with Path.anchor comparison
* Fix infinite loop in _studio.py path traversal

* test: Add tests for the new root path exploration

* Fix formatting style

* Fixed line to long

* Fix docstyle by running black manually

* Fix testcase with \\ when running on non-windows machines

* Fix formatting style

* cleanup unused import
mollyheamazon added a commit to mollyheamazon/sagemaker-python-sdk that referenced this pull request Apr 8, 2025
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744156034 -0700

parent fb22b91
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744155953 -0700

parent fb22b91
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744155703 -0700

parent fb22b91
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744155683 -0700

Test py312 ci support

Test py312 ci support

first commit

test to point to personal stack

changed tox.ini

Revert "changed tox.ini"

This reverts commit 696cb47.

Revert "Revert "changed tox.ini""

This reverts commit 5d35bd0.

Revert "Revert "Revert "changed tox.ini"""

This reverts commit 2ab95fb.

Revert "Revert "changed tox.ini""

This reverts commit 5d35bd0.

Revert "changed tox.ini"

This reverts commit 696cb47.

Revert "test to point to personal stack"

This reverts commit 49de844.

Revert "first commit"

This reverts commit 1374184.

add pyproject.toml

add py312 to ci

bump numpy version

numpy version change

add py312

upgrade pip version

add setuptools wheel to tox.ini

add pyyaml version constraint, remove py312 from docstring because there is no py312 image yet

update pyyaml version constraint

update pyyaml version constraint

deprecate py38

bump scipy

bump tensorflow and tensorboard

bump dill

bump apache-airflow to ensure dill and greenlet version

remove constraint for apache-airflow

remove constraint for apache-airflow

bump torch version

bump torchvision version

new tests

try changing some tests

update model trainer test

fix test_pipeline

add constraint to apache in tox

Fix key error in _send_metrics() (aws#5068)

Co-authored-by: pintaoz <[email protected]>

Use sagemaker session's s3_resource in download_folder (aws#5064)

Co-authored-by: pintaoz <[email protected]>

Fix error when there is no session to call _create_model_request() (aws#5062)

* Fix error when there is no session to call _create_model_request()

* Fix codestyle

---------

Co-authored-by: pintaoz <[email protected]>

Ensure Model.is_repack() returns a boolean (aws#5060)

* Ensure Model.is_repack() returns a boolean

* update test

---------

Co-authored-by: pintaoz <[email protected]>

feat: Make DistributedConfig Extensible (aws#5039)

* feat: Make DistributedConfig Extensible

* pylint

* Include none types when creating config jsons for safer reference

* fix: update test to account for changes

* format

* Add integ test

* pylint

* prepare release v2.240.0

* update development version to v2.240.1.dev0

* Fix key error in _send_metrics() (aws#5068)

Co-authored-by: pintaoz <[email protected]>

* fix: Added check for the presence of model package group before creating one (aws#5063)

Co-authored-by: Keshav Chandak <[email protected]>

* Use sagemaker session's s3_resource in download_folder (aws#5064)

Co-authored-by: pintaoz <[email protected]>

* remove union

* fix merge artifact

* Change dir path to distributed_drivers

* update paths

---------

Co-authored-by: ci <ci>
Co-authored-by: pintaoz-aws <[email protected]>
Co-authored-by: pintaoz <[email protected]>
Co-authored-by: Keshav Chandak <[email protected]>
Co-authored-by: Keshav Chandak <[email protected]>

Skip tests with deprecated instance type (aws#5077)

Co-authored-by: pintaoz <[email protected]>

pipeline definition function doc update (aws#5074)

Co-authored-by: Rohan Gujarathi <[email protected]>

feat: add integ tests for training JumpStart models in private hub (aws#5076)

* feat: add integ tests for training JumpStart models in private hub

* fixed formatting

* remove unused imports

* fix unused imports

* fix unit test failure and fix bug around versioning

* fix formatting

* fix unit tests

* fix model_uri usage issue

* fix some formatting

* separate private hub setup code

* add try catch block

* fix flake8 issue so except clause is not bare

* black formatting

fix: resolve infinite loop in _find_config on Windows systems (aws#4970)

* fix: resolve Windows path handling in _find_config

* Replace Path.match("/") with Path.anchor comparison
* Fix infinite loop in _studio.py path traversal

* test: Add tests for the new root path exploration

* Fix formatting style

* Fixed line to long

* Fix docstyle by running black manually

* Fix testcase with \\ when running on non-windows machines

* Fix formatting style

* cleanup unused import

change: update image_uri_configs  03-11-2025 07:18:09 PST

Fixing Pytorch training python version in tests (aws#5084)

* Fixing Pytorch training python version in tests

* Updating Inference test handling

remove s3 output location requirement from hub class init (aws#5081)

* remove s3 output location requirement from hub class init

* fix integ test hub

* lint

* fix test

---------

Co-authored-by: Gokul Anantha Narayanan <[email protected]>

fix: Prevent RunContext overlap between test_run tests (aws#5083)

Co-authored-by: Gokul Anantha Narayanan <[email protected]>

remove py38 from unit testing

fix integ test by bumping py38 to py39 for PyTorch

change framework_version that supports py39 in integ tests

remove py38 from unit testing

Update estimator.py
mollyheamazon added a commit to mollyheamazon/sagemaker-python-sdk that referenced this pull request Apr 16, 2025
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744156034 -0700

parent fb22b91
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744155953 -0700

parent fb22b91
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744155703 -0700

parent fb22b91
author Molly He <[email protected]> 1740529460 -0800
committer Molly He <[email protected]> 1744155683 -0700

Test py312 ci support

Test py312 ci support

first commit

test to point to personal stack

changed tox.ini

Revert "changed tox.ini"

This reverts commit 696cb47.

Revert "Revert "changed tox.ini""

This reverts commit 5d35bd0.

Revert "Revert "Revert "changed tox.ini"""

This reverts commit 2ab95fb.

Revert "Revert "changed tox.ini""

This reverts commit 5d35bd0.

Revert "changed tox.ini"

This reverts commit 696cb47.

Revert "test to point to personal stack"

This reverts commit 49de844.

Revert "first commit"

This reverts commit 1374184.

add pyproject.toml

add py312 to ci

bump numpy version

numpy version change

add py312

upgrade pip version

add setuptools wheel to tox.ini

add pyyaml version constraint, remove py312 from docstring because there is no py312 image yet

update pyyaml version constraint

update pyyaml version constraint

deprecate py38

bump scipy

bump tensorflow and tensorboard

bump dill

bump apache-airflow to ensure dill and greenlet version

remove constraint for apache-airflow

remove constraint for apache-airflow

bump torch version

bump torchvision version

new tests

try changing some tests

update model trainer test

fix test_pipeline

add constraint to apache in tox

Fix key error in _send_metrics() (aws#5068)

Co-authored-by: pintaoz <[email protected]>

Use sagemaker session's s3_resource in download_folder (aws#5064)

Co-authored-by: pintaoz <[email protected]>

Fix error when there is no session to call _create_model_request() (aws#5062)

* Fix error when there is no session to call _create_model_request()

* Fix codestyle

---------

Co-authored-by: pintaoz <[email protected]>

Ensure Model.is_repack() returns a boolean (aws#5060)

* Ensure Model.is_repack() returns a boolean

* update test

---------

Co-authored-by: pintaoz <[email protected]>

feat: Make DistributedConfig Extensible (aws#5039)

* feat: Make DistributedConfig Extensible

* pylint

* Include none types when creating config jsons for safer reference

* fix: update test to account for changes

* format

* Add integ test

* pylint

* prepare release v2.240.0

* update development version to v2.240.1.dev0

* Fix key error in _send_metrics() (aws#5068)

Co-authored-by: pintaoz <[email protected]>

* fix: Added check for the presence of model package group before creating one (aws#5063)

Co-authored-by: Keshav Chandak <[email protected]>

* Use sagemaker session's s3_resource in download_folder (aws#5064)

Co-authored-by: pintaoz <[email protected]>

* remove union

* fix merge artifact

* Change dir path to distributed_drivers

* update paths

---------

Co-authored-by: ci <ci>
Co-authored-by: pintaoz-aws <[email protected]>
Co-authored-by: pintaoz <[email protected]>
Co-authored-by: Keshav Chandak <[email protected]>
Co-authored-by: Keshav Chandak <[email protected]>

Skip tests with deprecated instance type (aws#5077)

Co-authored-by: pintaoz <[email protected]>

pipeline definition function doc update (aws#5074)

Co-authored-by: Rohan Gujarathi <[email protected]>

feat: add integ tests for training JumpStart models in private hub (aws#5076)

* feat: add integ tests for training JumpStart models in private hub

* fixed formatting

* remove unused imports

* fix unused imports

* fix unit test failure and fix bug around versioning

* fix formatting

* fix unit tests

* fix model_uri usage issue

* fix some formatting

* separate private hub setup code

* add try catch block

* fix flake8 issue so except clause is not bare

* black formatting

fix: resolve infinite loop in _find_config on Windows systems (aws#4970)

* fix: resolve Windows path handling in _find_config

* Replace Path.match("/") with Path.anchor comparison
* Fix infinite loop in _studio.py path traversal

* test: Add tests for the new root path exploration

* Fix formatting style

* Fixed line to long

* Fix docstyle by running black manually

* Fix testcase with \\ when running on non-windows machines

* Fix formatting style

* cleanup unused import

change: update image_uri_configs  03-11-2025 07:18:09 PST

Fixing Pytorch training python version in tests (aws#5084)

* Fixing Pytorch training python version in tests

* Updating Inference test handling

remove s3 output location requirement from hub class init (aws#5081)

* remove s3 output location requirement from hub class init

* fix integ test hub

* lint

* fix test

---------

Co-authored-by: Gokul Anantha Narayanan <[email protected]>

fix: Prevent RunContext overlap between test_run tests (aws#5083)

Co-authored-by: Gokul Anantha Narayanan <[email protected]>

remove py38 from unit testing

fix integ test by bumping py38 to py39 for PyTorch

change framework_version that supports py39 in integ tests

remove py38 from unit testing

Update estimator.py
mollyheamazon pushed a commit that referenced this pull request Apr 21, 2025
* fix: resolve Windows path handling in _find_config

* Replace Path.match("/") with Path.anchor comparison
* Fix infinite loop in _studio.py path traversal

* test: Add tests for the new root path exploration

* Fix formatting style

* Fixed line to long

* Fix docstyle by running black manually

* Fix testcase with \\ when running on non-windows machines

* Fix formatting style

* cleanup unused import
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.

6 participants