Repository navigation
|
We are seeing repeated PostgreSQL warnings when running Marten async daemon in HotCold mode across multiple application hosts. Observed PostgreSQL warning:
Sample: With additional Npgsql command logging enabled, the nearby statements are: and then: This appears to come from the Postgres advisory lock acquisition path used for daemon coordination. Why this matters:It produces repeated WARNING entries in PostgreSQL logs Expectation:Either this path should avoid SET LOCAL when not operating inside a transaction if possible Environment:Marten 8.26.0 |
Replies: 4 comments 2 replies
|
@Meryovi Try setting |
|
I created a minimal repro for this issue. You can run it with I wasn't able to make the warning appear continuously like we see in our containers. My assumption is that this happens because this setup isn't a real cluster, so there's no actual leader election. That said, the warning still appears regardless of whether #!/usr/bin/env dotnet
#:sdk Microsoft.NET.Sdk
#:property TargetFramework=net10.0
#:property LangVersion=preview
#:property Nullable=enable
#:property PublishAot=false
#:package Marten@8.26.1
#:package Testcontainers.PostgreSql@4.11.0
#:package Microsoft.Extensions.Hosting@10.0.5
#:package Microsoft.Extensions.Logging.Console@10.0.5
using DotNet.Testcontainers.Builders;
using JasperFx;
using JasperFx.Events.Daemon;
using JasperFx.Events.Projections;
using Marten;
using Marten.Events.Aggregation;
using Microsoft.Extensions.Hosting;
using Microsoft.Extensions.Logging;
using Testcontainers.PostgreSql;
var postgres = new PostgreSqlBuilder("postgres:18-alpine")
.WithDatabase("marten_db")
.WithUsername("postgres")
.WithPassword("postgres")
.WithOutputConsumer(Consume.RedirectStdoutAndStderrToConsole())
.Build();
await postgres.StartAsync();
Console.WriteLine("Postgres started");
var builder = Host.CreateApplicationBuilder(args);
builder.Logging.ClearProviders();
builder.Logging.AddSimpleConsole(options =>
{
options.SingleLine = true;
options.TimestampFormat = "HH:mm:ss.fff ";
});
builder.Logging.SetMinimumLevel(LogLevel.Warning);
builder.Services
.AddMarten(options =>
{
options.Connection(postgres.GetConnectionString());
options.AutoCreateSchemaObjects = AutoCreate.All;
options.Events.UseMonitoredAdvisoryLock = false; // Doesn't change the result.
options.Projections.Add<UserProjection>(ProjectionLifecycle.Async);
})
.AddAsyncDaemon(DaemonMode.HotCold);
using var host = builder.Build();
await host.StartAsync();
Console.WriteLine("Marten host started. Press any key to stop.");
Console.ReadKey();
await host.StopAsync();
await postgres.DisposeAsync();
public record UserRegistered(Guid UserId, string Name);
public sealed record UserView(Guid Id, string Name);
public sealed class UserProjection : SingleStreamProjection<UserView, Guid>
{
public static UserView Create(UserRegistered @event) =>
new(@event.UserId, @event.Name);
} |
|
Sup guys, a few extra What's happeningIn public bool HasLock(int lockId)
{
var lockState = _handles.TryGetValue(lockId, out var handle);
if (lockState && _options.LockMonitoringEnabled)
{
return !handle!.HandleLostToken.IsCancellationRequested;
}
return lockState;
}
The "older Marten version of AdvisoryLock" the flag conceptually toggles back to was removed when Weasel consolidated onto Medallion, so there is currently no code path for the flag to select. Two distinct problemsThese are separate issues and worth disentangling:
The PRs honor the flag's documented semantics. The Medallion warnings are a separate story, fixable independently, and I'd defer to Medallion's maintainer for that one. The default should remain Proposed fix (additive, no breaking changes)Two small companion PRs, both Draft:
A Testcontainers + PG 18 repro confirmed both the current behavior and the fix. The new theory tests parametrize both modes against the same contract, so any future divergence breaks the build. With the change in place, Totally fine if you'd rather just close this out by updating the docs to match reality and letting users open the Medallion issue themselves. The PRs are there as the "no magic, just honor what the flag says" option in case the diagnosis lands. |
|
This will be fixed in the next release. |
This will be fixed in the next release.