-
Notifications
You must be signed in to change notification settings - Fork 35
fix(agent): stop scoped-session S3 hang in baseline build + reap hung suites + early ACK #616
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
Open
isadeks
wants to merge
2
commits into
pr/ecs-test-hygiene
Choose a base branch
from
fix/615-ecs-scoped-session-hang
base: pr/ecs-test-hygiene
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+186
−19
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| """Fixture-free regression guard for the ECS test-hang scrub (#615 / #616 B1). | ||
|
|
||
| This module deliberately has NO local autouse fixture. It exists to prove that | ||
| conftest's ``_clean_env`` autouse fixture strips ``AGENT_SESSION_ROLE_ARN`` from | ||
| the environment before each test — the exact line the #615 fix adds to | ||
| ``_AGENT_ENV_VARS``. | ||
|
|
||
| Why a separate module: ``test_aws_session.py`` has its OWN autouse ``_reset`` | ||
| fixture that does ``monkeypatch.delenv(SESSION_ROLE_ARN_ENV)``, so a guard placed | ||
| there passes even if the conftest scrub is deleted (it asserts what the local | ||
| fixture guarantees, not what the fix does — #616 review B1). Here, only conftest's | ||
| ``_clean_env`` is in play. | ||
|
|
||
| Why set the var at MODULE IMPORT time (not in the test body): pytest autouse | ||
| fixtures run during test *setup*, before the body executes — so a | ||
| ``monkeypatch.setenv`` inside the test can't be scrubbed by them. Poisoning the | ||
| process env at import time (before any fixture runs) means the conftest scrub is | ||
| the only thing that can clear it by the time a test body reads it. Remove the | ||
| ``AGENT_SESSION_ROLE_ARN`` line from conftest's ``_AGENT_ENV_VARS`` and BOTH tests | ||
| below fail — a true bidirectional guard. | ||
|
|
||
| The bug this guards: with ``AGENT_SESSION_ROLE_ARN`` set, ``aws_session`` | ||
| resolves a *scoped* session and ``tenant_client`` returns ``session.client(...)``, | ||
| bypassing a ``@patch("boto3.client")`` mock. A mocked test (e.g. | ||
| ``test_attachments``) then makes a REAL S3 call that hangs forever on the ECS | ||
| network (no egress) in a socket read SIGALRM can't interrupt — stalling the whole | ||
| ``mise run build``. | ||
| """ | ||
|
|
||
| import os | ||
|
|
||
| from aws_session import SESSION_ROLE_ARN_ENV, is_scoped | ||
|
|
||
| # Poison the process env at import time — BEFORE any fixture runs. The conftest | ||
| # `_clean_env` autouse must scrub this for the assertions below to hold. | ||
| os.environ[SESSION_ROLE_ARN_ENV] = "arn:aws:iam::123456789012:role/leaked-from-parent-env" | ||
|
|
||
|
|
||
| def test_conftest_scrubs_session_role_arn(): | ||
| # If conftest's _clean_env strips AGENT_SESSION_ROLE_ARN, it is gone here even | ||
| # though the module poisoned it at import time. If the scrub line is removed, | ||
| # this fails — the guard the #615 fix actually needs. | ||
| assert os.environ.get(SESSION_ROLE_ARN_ENV) is None | ||
|
|
||
|
|
||
| def test_session_resolves_unscoped_when_scrubbed(): | ||
| # With the var scrubbed (and the cache reset, both by conftest _clean_env) a | ||
| # bare get_session() must be unscoped — the path where boto3.client mocks | ||
| # intercept, so no real S3 call is made and nothing hangs. | ||
| assert is_scoped() is False |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nit (safety window).
_reap_on_hangcallsos._exit(1)unconditionally.daemon=Truestops the timer from blocking shutdown, but not from firing if a slow-but-passing suite lands near 600s (e.g. mid coverage-write in teardown), turning a green run red with a thread-dump uncorrelated to any failed test. Cancel on session finish so it only fires on a true hang: