Describe the bug
When using Marten with wolverine projection distribution and a PostgreSQL connection string with a Unix socket we started seeing the error "Failed to start requested agent" with an IndexOutOfRangeException from JasperFx.Descriptors.DatabaseId.Parse. We encountered this after trying to update to the new versions of Marten and Wolverine in GCP Cloud Run with GCP Cloud SQL.
This happens because DatabaseId (derived from the connection string Host) contains slashes (e.g., /cloudsql/...), which causes the Uri used in EventSubscriptionAgentFamily to be parsed into multiple segments. This shifts the expected segment index for DatabaseId in BuildAgentAsync and splits the ID, preventing DatabaseId.Parse from receiving the correct full string.
To Reproduce
Steps to reproduce the behavior:
- Configure Marten with a connection string pointing to a Unix socket (e.g.,
Host=/tmp/postgresql;Database=mydb) and wolverine projection distribution.
- Run the application.
- See error
IndexOutOfRangeException at JasperFx.Descriptors.DatabaseId.Parse.
Expected behavior
Wolverine should correctly parse the DatabaseId and start agents when the connection string uses a Unix socket path containing slashes.
Additional context
Stack Trace:
System.IndexOutOfRangeException: Index was outside the bounds of the array.
at JasperFx.Descriptors.DatabaseId.Parse(String text) in /_/src/JasperFx/Descriptors/DatabaseId.cs:line 12
at Wolverine.Marten.Distribution.EventSubscriptionAgentFamily.BuildAgentAsync(Uri uri, IWolverineRuntime wolverineRuntime) in /home/runner/work/wolverine/wolverine/src/Persistence/Wolverine.Marten/Distribution/EventSubscriptionAgentFamily.cs:line 50
at Wolverine.Runtime.Agents.NodeAgentController.StartAgentAsync(Uri agentUri) in /home/runner/work/wolverine/wolverine/src/Wolverine/Runtime/Agents/NodeAgentController.cs:line 164
at Wolverine.Runtime.Agents.StartAgents.ExecuteAsync(IWolverineRuntime runtime, CancellationToken cancellationToken) in /home/runner/work/wolverine/wolverine/src/Wolverine/Runtime/Agents/StartAgents.cs:line 71
Analysis:
The EventSubscriptionAgentFamily.UriFor method constructs a URI by directly embedding the DatabaseId string into the path. If databaseId contains / (which is required when using a unix socket connection), the Uri class parses it as multiple path segments. BuildAgentAsync hardcodes retrieving Segments[2], which is incorrect when the ID spans multiple segments.
Minimal Reproduction:
using JasperFx.Descriptors; // Assuming reference
public void Run()
{
var host = "/tmp/postgresql";
var database = "mydb";
var databaseId = $"{host}.{database}";
// Emulating EventSubscriptionAgentFamily.UriFor logic
// URI becomes: event-subscriptions://marten/main//tmp/postgresql.mydb/some/shard
var uriString = $"event-subscriptions://marten/main/{databaseId}/some/shard";
var uri = new Uri(uriString);
// Emulating BuildAgentAsync logic
// Fails here because Segments[2] is just "/" (due to double slash)
// instead of the full "/tmp/postgresql.mydb"
var databaseIdPart = uri.Segments[2].Trim('/');
// Throws IndexOutOfRangeException because databaseIdPart does not contain '.'
var id = DatabaseId.Parse(databaseIdPart);
}
Describe the bug
When using Marten with wolverine projection distribution and a PostgreSQL connection string with a Unix socket we started seeing the error "Failed to start requested agent" with an IndexOutOfRangeException from JasperFx.Descriptors.DatabaseId.Parse. We encountered this after trying to update to the new versions of Marten and Wolverine in GCP Cloud Run with GCP Cloud SQL.
This happens because
DatabaseId(derived from the connection string Host) contains slashes (e.g.,/cloudsql/...), which causes theUriused inEventSubscriptionAgentFamilyto be parsed into multiple segments. This shifts the expected segment index forDatabaseIdinBuildAgentAsyncand splits the ID, preventingDatabaseId.Parsefrom receiving the correct full string.To Reproduce
Steps to reproduce the behavior:
Host=/tmp/postgresql;Database=mydb) and wolverine projection distribution.IndexOutOfRangeExceptionatJasperFx.Descriptors.DatabaseId.Parse.Expected behavior
Wolverine should correctly parse the
DatabaseIdand start agents when the connection string uses a Unix socket path containing slashes.Additional context
Stack Trace:
Analysis:
The
EventSubscriptionAgentFamily.UriFormethod constructs a URI by directly embedding theDatabaseIdstring into the path. IfdatabaseIdcontains/(which is required when using a unix socket connection), theUriclass parses it as multiple path segments.BuildAgentAsynchardcodes retrievingSegments[2], which is incorrect when the ID spans multiple segments.Minimal Reproduction: