Skip to content

Possible fix for port exhaustion during integration tests#1719

Closed
WhitWaldo wants to merge 3 commits intodapr:masterfrom
WhitWaldo:port-exhaustion-fix
Closed

Possible fix for port exhaustion during integration tests#1719
WhitWaldo wants to merge 3 commits intodapr:masterfrom
WhitWaldo:port-exhaustion-fix

Conversation

@WhitWaldo
Copy link
Copy Markdown
Contributor

Description

Frequently, integration tests fail during CICD in GitHub due to ports not being assigned exclusively, leading to the tests failing because of a lack of gRPC connectivity. This is an attempt to remedy that issue.

Issue reference

We strive to have all PR being opened based on an issue, where the problem or feature have been discussed prior to implementation.

Please reference the issue this PR will close: #[issue number]

Checklist

Please make sure you've completed the relevant tasks for this PR, out of the following list:

  • Code compiles correctly
  • Created/updated tests
  • Extended the documentation

Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@WhitWaldo WhitWaldo added this to the v1.17 milestone Feb 21, 2026
@WhitWaldo WhitWaldo self-assigned this Feb 21, 2026
@WhitWaldo WhitWaldo requested review from a team as code owners February 21, 2026 20:48
Copy link
Copy Markdown

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 attempts to reduce flaky CI integration test failures caused by host-port collisions (and resulting gRPC connectivity issues) by introducing TCP port reservations when pre-assigning Dapr sidecar ports in the app-first startup flow.

Changes:

  • Add PortReservation + PortUtilities.ReserveTcpPort() to temporarily reserve host TCP ports.
  • Update app-first startup (DaprTestApplicationBuilder.BuildAndStartAsync) to reserve HTTP/gRPC ports before configuring the harness/app, then release reservations prior to initializing the harness.
  • Re-implement GetAvailablePort() on top of ReserveTcpPort().

Reviewed changes

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

File Description
src/Dapr.Testcontainers/Common/Testing/DaprTestApplicationBuilder.cs Uses port reservations when pre-assigning Dapr HTTP/gRPC ports in app-first mode; adds cleanup logic.
src/Dapr.Testcontainers/Common/PortUtilities.cs Introduces reservable TCP ports and updates GetAvailablePort() to use the reservation mechanism.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment on lines +156 to 162
// Release port reservations just before daprd starts to minimize collisions.
httpReservation.Dispose();
grpcReservation.Dispose();
httpReservation = null;
grpcReservation = null;

await harness.InitializeAsync();
Comment thread src/Dapr.Testcontainers/Common/PortUtilities.cs Outdated
Comment on lines +131 to +133
// Pre-assign ports so the app knows where Dapr will be (avoid collisions)
httpReservation = PortUtilities.ReserveTcpPort();
do
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Signed-off-by: Whit Waldo <whit.waldo@innovian.net>
@WhitWaldo WhitWaldo closed this Apr 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants