Repository navigation
Open
Labels
area-integrationsIssues pertaining to Aspire Integrations packageskafkaIssues related to Kafka integrations
Milestone
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
A Kafka dependency is restarted each time I run the AppHost project.
Minimal reproduction code:
var kafka = builder
.AddKafka("messaging").WithLifetime(ContainerLifetime.Persistent);
I am on MacOS, using Docker Desktop
Happy to provide further details as necessary
Thank you
Expected Behavior
No response
Steps To Reproduce
No response
Exceptions (if any)
No response
AppHost CSProj
<Project Sdk="Microsoft.NET.Sdk">
<Sdk Name="Aspire.AppHost.Sdk" Version="9.0.0" />
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net8.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<IsAspireHost>true</IsAspireHost>
<UserSecretsId>*****</UserSecretsId>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Aspire.Hosting.AppHost" Version="9.0.0" />
<PackageReference Include="Aspire.Hosting.Kafka" Version="9.0.0" />
<PackageReference Include="Aspire.Npgsql" Version="9.0.0" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\..\Domain\Demo\DemoApp\DemoApp.csproj" />
</ItemGroup>
</Project>
.NET Version info
dotnet --info
.NET SDK:
Version: 8.0.100
Commit: 57efcf1350
Workload version: 8.0.100-manifests.4d7d414a
Runtime Environment:
OS Name: Mac OS X
OS Version: 14.4
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.100/
.NET workloads installed:
Workload version: 8.0.100-manifests.4d7d414a
There are no installed workloads to display.
Host:
Version: 8.0.0
Architecture: arm64
Commit: 5535e31a71
.NET SDKs installed:
8.0.100 [/usr/local/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 8.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Other architectures found:
x64 [/usr/local/share/dotnet/x64]
registered at [/etc/dotnet/install_location_x64]
Environment variables:
Not set
global.json file:
Not found
Anything else?
No response
Reacted by Michael, Manuel Baumann and siavol
Metadata
Metadata
Assignees
Labels
area-integrationsIssues pertaining to Aspire Integrations packageskafkaIssues related to Kafka integrations
Activity
amolenk commentedon Nov 26, 2024
Seeing the same behavior
duskembayev commentedon Dec 18, 2024
Defining the port solves the problem.
fredeil commentedon Feb 19, 2025
Currently experiencing the same on .NET9
davidfowl commentedon Mar 3, 2025
David Negstad (@danegsta) there should be a log that explains why the container isn't being persistent right?
danegsta commentedon Mar 3, 2025
Yeah, setting the Aspire.Hosting.Dcp LogLevel to information should show a log message when we recreate a persistent container. Log entry starts with “found existing Container, but the lifecycle key doesn't match, recreating container” and should then give a high level breakdown of what properties have changed (ports, environment variables, bind mounts, etc.).
davidfowl commentedon Mar 3, 2025
David Negstad (@danegsta) I think we should log that in warning by default but log the more verbose information as information.
danegsta commentedon Mar 3, 2025
The logging library that we're basically forced to use (it's standard in all our dependencies) has explicitly chosen not to support warning level logging (apparently the author read a blog that said warnings are bad so now we're not allowed to use them). Practically speaking we're limited to error, info, and debug log levels.
lwu-st commentedon May 29, 2025
This issue is still present on 9.3.0, and the workaround by specifying a port doesn't work for us either.
Does anyone have any other workaround that may be worth trying?
This is especially detrimental to integration test time consumption, as each run will reprovision Kafka.
davidfowl commentedon May 29, 2025
Did anyone turn on the logging that explains why the container is getting restarted?
lwu-st commentedon May 29, 2025
David Fowler (@davidfowl) just retrieved it:
davidfowl commentedon May 29, 2025
David Negstad (@danegsta) ?
danegsta commentedon May 29, 2025
This is basically the predictable persistent container ports issue; by default Kafka is getting a random proxied host port every run which causes the ports reported in the
KAFKA_ADVERTISED_LISTENERSenvironment variable to change despite being configured with what should be a fixed port of 9092. You should be able to opt the resource into running proxyless by adding the experimental.WithEndpointProxySupport(false)which would prevent the environment variable changing every run.artur-st commentedon May 30, 2025
Workaround worked for me 🚀
Odonno commentedon Aug 19, 2025
The same issue happens with Kafka and goff (from CommunityToolkit). However, the SQL Server hosting works as expected.
I can also notice that the volume is not destroyed when the container is stopped/recreated, which causes issues as more volumes exist at the same time. Is it a side effect or could it be the cause?