Skip to content

Marten projection distribution fails to start agents when using a unix socket connection #2016

@RonTamG

Description

@RonTamG

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:

  1. Configure Marten with a connection string pointing to a Unix socket (e.g., Host=/tmp/postgresql;Database=mydb) and wolverine projection distribution.
  2. Run the application.
  3. 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); 
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions