Skip to content

Fixed proxy Issue #5225

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 4 commits into
base: master
Choose a base branch
from
Open

Conversation

raujaiswal
Copy link
Contributor

@raujaiswal raujaiswal commented May 26, 2025

Context

Issue: Publishing test run data from behind corporate proxy fails with socket timeout error while accessing ufxtcmprodweu21.vstmrblob.vsassets.io:443

Work item link

Icm link

Description

Customers have set-up agent locally behind corporate proxy where they failed to publish test run data and get the below error.

  Microsoft.Azure.Storage.StorageException: A connection attempt failed because the connected party did not properly 
  respond after a period of time, or established connection failed because connected host has failed to respond. 
  (ufxtcmprodweu21.vstmrblob.vsassets.io:443)

Why it happened?

  • We are setting the proxy in VSSUtil that helps configure VSS (Azure DevOps) client settings, but it does not globally enforce proxy settings for all HTTP clients in the process.

  • WebApi (and other SDKs) often create their own HttpClient or connection objects, which may not automatically pick up the proxy settings from VssUtil unless explicitly configured.
    Example:
    image

How is Issue reproduced locally?

We have attempted to recreate by doing the following.

  1. Setup up a self-hosted Agent behind a proxy Doc

  2. Configure a local proxy using Fiddler.

  3. Restrict all outbound traffic to the Agent.Listener and the Agent.Worker processes.

:: Block all outbound for the Agent.Listener
netsh advfirewall firewall add rule name="Block Agent.Listener Outbound" dir=out action=block program="C:\agent\_layout\win-x64\bin\Agent.Listener.exe" enable=yes

:: Block all outbound for the Agent.Worker
netsh advfirewall firewall add rule name="Block Agent.Worker Outbound" dir=out action=block program="C:\agent\_layout\win-x64\bin\Agent.Worker.exe" enable=yes
  1. Allow Agent.Listener and the Agent.Worker processes to only access the Local Proxy (127.0.0.1)
netsh advfirewall firewall add rule name="Allow Agent.Listener to Proxy" dir=out action=allow program="C:\agent\_layout\win-x64\bin\Agent.Listener.exe" remoteip=127.0.0.1 enable=yes
netsh advfirewall firewall add rule name="Allow Agent.Worker to Proxy" dir=out action=allow program="C:\agent\_layout\win-x64\bin\Agent.Worker.exe" remoteip=127.0.0.1 enable=yes

  1. Configure a test pipeline to use the same vso command as used by the customer to publish a sample TRX file.

    $resultFile = '$(Build.SourcesDirectory)\c984c06c-792d-408e-a73b-a5e0505a9b8e.trx'
    Write-Host "##vso[results.publish type=VsTest;mergeResults=false;publishRunAttachments=true;resultFiles=$resultFile;]"
    
  2. By default, Fiddler on starting, sets proxy for entire process running in the system. So, we need to disable it by manipulating.

    Go to setting -> Network&Internet -> edit (use a proxy server)
    change value from http=127.0.0.1:8888;https=127.0.0.1:8888 to http=127.0.0.1:8888;httpsgh=127.0.0.1:8888

Solution:

  • ProxyUtil.SetDefaultHttpClientProxy is used to ensure that the default .NET HttpClient (and any new HttpClientHandler instances) are also configured to use the correct proxy. This is necessary because some libraries or SDKs may not use the same static/global settings as VssUtil.

Risk Assessment (Low / Medium / High)

Medium

Unit Tests Added or Updated (Yes / No)

Indicate whether unit tests were added or modified to reflect the changes.

Added test case in canary repo PR:
https://github.com/microsoft/azure-pipelines-canary/pull/1196

Currently Test case is failing with latest agent Version:
Failure Pipeline Link

Test Case is getting passed when taking Agent from this branch users/raunakjaiswalMS/fixingProxyIssue
Passed Pipeline Link

Additional Testing Performed

List manual or automated tests performed beyond unit tests (e.g., integration, scenario, regression).

Reproducing the issue by locally following above steps:

When default proxy is set to httpClient in worker process only:

When default proxy is set to httpClient in Listener process only:

azure-pipelines-bot added 2 commits May 21, 2025 13:58
amankumar030

This comment was marked as off-topic.

…-agent into users/raunakjaiswalMS/fixingProxyIssue

# Please enter a commit message to explain why this merge is necessary,
# especially if it merges an updated upstream into a topic branch.
#
# Lines starting with '#' will be ignored, and an empty message aborts
# the commit.
Copy link

@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 addresses a socket timeout error when publishing test run data from behind a corporate proxy by ensuring the default .NET HttpClient is configured with the correct proxy settings.

  • Sets the global HttpClient proxy settings in both the Worker and Listener processes.
  • Introduces a new ProxyUtil class to centralize proxy configuration for all new HttpClientHandler instances.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated no comments.

File Description
src/Agent.Worker/Worker.cs Configures the default HttpClient proxy before initializing the VSS client settings.
src/Agent.Sdk/Util/ProxyUtil.cs Defines a utility to set HttpClient.DefaultProxy for global proxy configuration.
src/Agent.Listener/Agent.cs Ensures the Listener process also applies the default proxy configuration before client initialization.

@raujaiswal raujaiswal marked this pull request as ready for review June 12, 2025 06:03
@raujaiswal raujaiswal requested review from a team as code owners June 12, 2025 06:03
@raujaiswal
Copy link
Contributor Author

/azp run

Copy link

Azure Pipelines successfully started running 1 pipeline(s).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants