Skip to content

Add explicit context checking for belt-and-suspenders safety in tenant isolation policy polling #801

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
wants to merge 9 commits into
base: main
Choose a base branch
from

Conversation

Copilot
Copy link
Contributor

@Copilot Copilot AI commented Jun 3, 2025

This PR addresses a potential issue with context-insensitive sleep logic in the tenant isolation policy polling function by adding explicit context checking for belt-and-suspenders safety.

Problem

While the underlying SleepWithContext implementation already correctly honors context cancellation, the polling logic in doWaitForLifecycleOperationStatus could benefit from explicit context checking before entering the sleep period to ensure immediate exit on context cancellation and prevent potential resource usage or delayed termination under heavy load or shutdown scenarios.

Changes

  1. Added explicit context check: Added a select statement with <-ctx.Done() case before calling SleepWithContext in the polling loop for additional safety
  2. Enhanced documentation: Updated the method comment to explicitly mention that the function respects context cancellation during sleep periods between polling attempts
  3. Preserved existing behavior: All existing functionality remains unchanged - this is purely an additive safety measure

Code Changes

// Before
err = client.Api.SleepWithContext(ctx, waitTime)
if err != nil {
    return nil, fmt.Errorf("polling interrupted: %w", err)
}

// After  
select {
case <-ctx.Done():
    return nil, ctx.Err()
default:
    // Wait before polling again (honors context cancellation)
    err = client.Api.SleepWithContext(ctx, waitTime)
    if err != nil {
        return nil, fmt.Errorf("polling interrupted: %w", err)
    }
}

Validation

  • ✅ Code builds successfully
  • ✅ Go formatting and vet checks pass
  • ✅ Underlying SleepWithContext tests continue to pass
  • ✅ Changes are minimal and surgical (12 additions, 5 deletions in single file)

This fix provides belt-and-suspenders safety by adding an explicit context check while maintaining all existing behavior and leveraging the already-correct context handling in SleepWithContext.

Fixes #800.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • checkpoint-api.hashicorp.com
    • Triggering command: /tmp/go-build952270432/b001/tenant_isolation_policy.test -test.testlogfile=/tmp/go-build952270432/b001/testlog.txt -test.paniconexit0 -test.timeout=10m0s -test.v=true -test.run=TestUnit (dns block)

If you need me to access, download, or install something from one of these locations, you can either:


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
@Copilot Copilot AI changed the title [WIP] [Copilot] Direct Polling with Context-Insensitive Sleep Logic (Resource Management) Add explicit context checking for belt-and-suspenders safety in tenant isolation policy polling Jun 3, 2025
@Copilot Copilot AI requested a review from mawasile June 3, 2025 12:05
Copilot finished work on behalf of mawasile June 3, 2025 12:05
@mawasile mawasile marked this pull request as ready for review June 3, 2025 12:57
@Copilot Copilot AI review requested due to automatic review settings June 3, 2025 12:57
@mawasile mawasile requested a review from a team as a code owner June 3, 2025 12:57
Copy link
Contributor

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull Request Overview

This PR improves the tenant isolation policy polling function by adding an explicit context check before entering the sleep period to ensure immediate cancellation response. Key changes include:

  • Inserting a select block to check for context cancellation before invoking SleepWithContext.
  • Updating the function documentation to mention that context cancellation is explicitly handled during sleep.
  • Preserving existing functionality while enhancing safety.

@mawasile
Copy link
Contributor

mawasile commented Jun 3, 2025

@copilot you need to create a changelog using changie

Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 3, 2025

@copilot you need to create a changelog using changie

Changelog entry created using changie in commit 8934fc5. The entry was added to .changes/unreleased/fixed-20250603-130329.yaml with the appropriate kind (fixed) and references issue #800.

Copilot finished work on behalf of mawasile June 3, 2025 13:04
@mawasile mawasile added ai assisted Pull requests that have be fully or partially implemented using Copilot or AI ai found Issues and Bugs that were found using AI copilot fixed using GitHub copilot autonomous agent labels Jun 3, 2025
Co-authored-by: mattdot <266258+mattdot@users.noreply.github.com>
Copy link
Contributor Author

Copilot AI commented Jun 4, 2025

Just as a heads up, I was blocked by some firewall rules while working on your feedback. Expand below for details.

Warning

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • http://168.63.129.16:80/machine/
    • Triggering command: /usr/bin/python3 -u bin/WALinuxAgent-2.13.1.1-py3.9.egg -collect-logs (http block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot finished work on behalf of mattdot June 4, 2025 19:13
mattdot
mattdot previously approved these changes Jun 5, 2025
Co-authored-by: mawasile <50197777+mawasile@users.noreply.github.com>
Copilot finished work on behalf of mawasile June 9, 2025 11:23
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ai assisted Pull requests that have be fully or partially implemented using Copilot or AI ai found Issues and Bugs that were found using AI copilot fixed using GitHub copilot autonomous agent
Projects
None yet
Development

Error loading sessions

Retrying...

Successfully merging this pull request may close these issues.

[Copilot] Direct Polling with Context-Insensitive Sleep Logic (Resource Management)
3 participants