Skip to content

Conversation

@GarrettBeatty
Copy link
Contributor

@GarrettBeatty GarrettBeatty commented Dec 10, 2025

Stacked PRs:


Description

Fix HTTP concurrency for multi part download. Previously we were releasing the http semaphore slot after we got the http response but before we read the response body (wrote it to a file/stream). This meant that it was possible for there to be more active ConcurrentServiceRequests than the user actually wanted.

The fix was to move the releasing of the http semaphore slot after processing the part. This ensured that its only released once its written to the file/stream and ensures only ConcurrentServiceRequests are active at a time.

Motivation and Context

#3806

Testing

  1. I added unit tests such as HttpSemaphore_HeldThroughProcessPartAsync which verify that the http semaphore is only released after process part is executed. In order to ensure this test actually checks the issue, i ran it before my fix and the test failed (as expected). After my fix, the test passes.
  2. dry run
"build_id": "7e8b2922-9aab-4b1c-8cf2-ee8c6ad6b8d1",
    "build_type": "DRY_RUN",
    "build_status": "SUCCEEDED",
    "created_time": "2025-12-09T19:44:19.400Z",
    "last_modified_time": "2025-12-09T22:47:24.680Z",

Screenshots (if appropriate)

Before (we can see concurrency is over the set 10)
image

After, we can see concurrency stays at or below 10
image

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to change)

Checklist

  • My code follows the code style of this project
  • My change requires a change to the documentation
  • I have updated the documentation accordingly
  • I have read the README document
  • I have added tests to cover my changes
  • All new and existing tests passed

License

  • I confirm that this pull request can be released under the Apache 2 license

Add tests

handle edge cases and add unit tets

update tests info

add integ tests

stack-info: PR: #4218, branch: GarrettBeatty/gcbeatty/taskoptimization/1
@GarrettBeatty GarrettBeatty force-pushed the GarrettBeatty/gcbeatty/taskoptimization/1 branch from 610a889 to 91abd13 Compare December 10, 2025 15:52
}
}

/// <summary>
Copy link
Contributor Author

Choose a reason for hiding this comment

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

i think we should eventually refactor this to get rid of the extra discoverdownloadstrategy function. since its a little confusing that the semaphore releases go across functions (between discoverdownloadstrategy and startdownload). i plan on doing that after we fix all of the bugs

@GarrettBeatty GarrettBeatty marked this pull request as ready for review December 10, 2025 16:37
}

[TestMethod]
public async Task DiscoverUsingPartStrategy_AcquiresAndReleasesHttpSlot()
Copy link
Contributor Author

Choose a reason for hiding this comment

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

these are no longer applicable since they asserted old (and incorrect behavior)

// Act - Start both discoveries concurrently
var task1 = coordinator1.DiscoverDownloadStrategyAsync(CancellationToken.None);
var task2 = coordinator2.DiscoverDownloadStrategyAsync(CancellationToken.None);
var discovery1 = await coordinator1.DiscoverDownloadStrategyAsync(CancellationToken.None);
Copy link
Contributor Author

Choose a reason for hiding this comment

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

had to update these because now with new change the semaphore is held through start download, so callers need to do discover + start download in order to get through the whole http cycle

@GarrettBeatty GarrettBeatty mentioned this pull request Dec 10, 2025
7 tasks
@GarrettBeatty GarrettBeatty merged commit f2e9a53 into feature/transfermanager Dec 11, 2025
4 checks passed
@GarrettBeatty GarrettBeatty deleted the GarrettBeatty/gcbeatty/taskoptimization/1 branch December 11, 2025 14:26
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.

3 participants