Skip to content

fix(EventHubs): Workaround health API timeout#1624

Merged
HofmeisterAn merged 1 commit intodevelopfrom
bugfix/fix-event-hubs
Jan 17, 2026
Merged

fix(EventHubs): Workaround health API timeout#1624
HofmeisterAn merged 1 commit intodevelopfrom
bugfix/fix-event-hubs

Conversation

@HofmeisterAn
Copy link
Copy Markdown
Collaborator

@HofmeisterAn HofmeisterAn commented Jan 17, 2026

What does this PR do?

Since the EventHubs image is not versioned, we unfortunately ran into an issue with the latest release. It appears that the health API call fails when the HTTP request is sent too early, causing the client to time out.

While we could catch the timeout or cancellation exception and retry once, the default HTTP timeout is 100 seconds, which would make users wait unnecessarily. It would be better for the EventHubs team to address this issue properly.

The same issue also occurs when using the CLI.

You can find more information here: Azure/azure-event-hubs-emulator-installer#69 (comment).

Why is it important?

Unblock our CI.

Related issues

-

Summary by CodeRabbit

  • Bug Fixes
    • Improved Event Hubs container initialization reliability with an enhanced wait strategy that now includes a startup delay before performing health status checks. This addresses timing-related issues that could prevent containers from starting properly and ensures more stable and predictable initialization behavior across deployment and integration testing workflows.

✏️ Tip: You can customize this high-level summary in your review settings.

@HofmeisterAn HofmeisterAn added the bug Something isn't working label Jan 17, 2026
@netlify
Copy link
Copy Markdown

netlify Bot commented Jan 17, 2026

Deploy Preview for testcontainers-dotnet ready!

Name Link
🔨 Latest commit 948ab50
🔍 Latest deploy log https://app.netlify.com/projects/testcontainers-dotnet/deploys/696b4bddc571180008410a0c
😎 Deploy Preview https://deploy-preview-1624--testcontainers-dotnet.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@coderabbitai
Copy link
Copy Markdown

coderabbitai Bot commented Jan 17, 2026

Walkthrough

The changes introduce a workaround for a GitHub issue in the EventHubs container builder by adding a custom wait strategy that delays 5 seconds before performing the existing HTTP health check. A global using directive for System.Threading.Tasks is also added.

Changes

Cohort / File(s) Summary
EventHubs wait strategy workaround
src/Testcontainers.EventHubs/EventHubsBuilder.cs
Adds private nested class WorkaroundGhIssue69 implementing IWaitUntil to provide a 5-second delay; modifies the wait strategy composition to chain this custom wait before the existing HTTP-based health check
Global using directives
src/Testcontainers.EventHubs/Usings.cs
Adds System.Threading.Tasks global using directive

Possibly related PRs

Suggested labels

test flakiness

Poem

🐰 A hop and a pause before we check,
Five seconds to calm any flaky deck,
EventHubs now waits with grace,
Before the HTTP embrace!

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

🚥 Pre-merge checks | ✅ 3
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title 'fix(EventHubs): Workaround health API timeout' clearly and concisely describes the main change: implementing a workaround for a health API timeout issue in EventHubs.
Description check ✅ Passed The PR description includes both required sections ('What does this PR do?' and 'Why is it important?') with substantive explanations of the change and its motivation, though the 'How to test this PR' section lacks testing instructions.
Docstring Coverage ✅ Passed Docstring coverage is 100.00% which is sufficient. The required threshold is 80.00%.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@HofmeisterAn
Copy link
Copy Markdown
Collaborator Author

HofmeisterAn commented Jan 17, 2026

Edit: A better version without an artificial delay:

.WithWaitStrategy(Wait.ForUnixContainer()
// https://github.com/Azure/azure-event-hubs-emulator-installer/issues/69#issuecomment-3762895979.
.UntilMessageIsLogged("Emulator Service is Successfully Up!")
.UntilHttpRequestIsSucceeded(request =>
request.ForPort(EventHubsHttpPort).ForPath("/health")));

TC users can work around this by overriding the default wait strategy and adding an artificial delay (WorkaroundGhIssue69) before sending the first health API call.

using DotNet.Testcontainers.Configurations;
using DotNet.Testcontainers.Containers;

...

_ = new EventHubsBuilder("mcr.microsoft.com/azure-messaging/eventhubs-emulator:latest")
    .WithAcceptLicenseAgreement(true)
    // Override the default wait strategy.
    .WithWaitStrategy(Wait.ForUnixContainer()
        .AddCustomWaitStrategy(new WorkaroundGhIssue69())
        .UntilHttpRequestIsSucceeded(request =>
            request.ForPort(EventHubsBuilder.EventHubsHttpPort).ForPath("/health")))
    .Build();
        
...

private sealed class WorkaroundGhIssue69 : IWaitUntil
{
    public async Task<bool> UntilAsync(IContainer container)
    {
        await Task.Delay(TimeSpan.FromSeconds(5))
            .ConfigureAwait(false);

        return true;
    }
}

@HofmeisterAn HofmeisterAn merged commit 994038c into develop Jan 17, 2026
16 checks passed
@HofmeisterAn HofmeisterAn deleted the bugfix/fix-event-hubs branch January 17, 2026 09:01
request.ForPort(EventHubsHttpPort).ForPath("/health")));
.WithWaitStrategy(Wait.ForUnixContainer()
.AddCustomWaitStrategy(new WorkaroundGhIssue69())
.UntilHttpRequestIsSucceeded(request =>
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

@HofmeisterAn could it be possible to loop on http call with a smaller (configurable) http timeout.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

No, I don't think this is possible without changing the HttpWaitStrategy implementation.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants