1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.
  2. Anuncie Aqui
    Anuncie aqui você Também: fdantas@4each.com.br

Error: Failed to invoke 'JoinGroup' due to an error on the server

Discussão em 'Angular' iniciado por WBuck, Setembro 13, 2024.

  1. WBuck

    WBuck Guest

    We're attempting to use Azure SignalR (with managed identities) with an Angular front end and ASP.net Core back end. For a particular method call I'll see the following error about 50% of the time:


    Error: Failed to invoke 'JoinGroup' due to an error on the server.
    ​

    We're supplying an object with 3 properties to the JoinGroup function. From the Angular application this looks like the following:

    const url = 'some url';

    const options: IHttpConnectionOptions = {
    accessTokenFactory: async () => await service.getToken(),
    transport: HttpTransportType.WebSockets,
    withCredentials: false
    };

    const hub = new HubConnectionBuilder()
    .withUrl(url, options)
    .configureLogging(LogLevel.Debug)
    .withAutomaticReconnect()
    .build();

    await hub.start();

    // This is the call that fails about 50% of the time.
    const msg = await this.hub.invoke<string>('JoinGroup', {
    organizationId: '1bf751e8-67cd-4fb0-89cc-206c31371ac1',
    environmentId: '02a03e43-839b-4f71-88b1-d809d26a0499',
    recoveryPlanId: '9c18d9b7-a58f-4f8f-8c46-aedc996dc304'
    });



    From the ASP.net core application our hub looks like the following:

    public async Task<string> JoinGroup(RecoveryGroupName group)
    {
    await Groups.AddToGroupAsync(Context.ConnectionId, group.ToString());
    return "You've joined a group!";
    }


    And the RecoveryGroupName looks like the following:

    public record RecoveryGroupName
    {
    public required Guid OrganizationId { get; init; }
    public required Guid EnvironmentId { get; init; }
    public required Guid RecoveryPlanId { get; init; }

    // Right now I'm just creating a new string here each time ToString is called.
    // Once I get this bloody this working I'll fix it.
    public override string ToString()
    => $"{OrganizationId}_{EnvironmentId}_{RecoveryPlanId}";
    }


    I can't figure out why this is happening!! I don't see any errors from the server (nothing in the logs or console when running locally).

    I've set EnableDetailedErrors to true but that made no difference.

    builder.Services
    .AddSignalR(opt => opt.EnableDetailedErrors = true)
    .AddAzureSignalR(option => /* Setting up connection string etc */);


    All I see in the browser is the following: [​IMG]

    Am I doing something wrong here? How can I troubleshoot this? There are no error messages!

    One thing I've noticed is if I set ServerStickyMode to Required I don't see the issue:

    builder.Services
    .AddSignalR(opt =>
    {
    opt.EnableDetailedErrors = true;

    })
    .AddAzureSignalR(option =>
    {
    option.ServerStickyMode = ServerStickyMode.Required;
    option.Endpoints =
    [
    new ServiceEndpoint(new Uri("ourUrl"), tokenCredential)
    ];
    })


    Why does this appear to fix my issue? I didn't think we needed sticky sessions since we're using Azure SignalR..

    Continue reading...

Compartilhe esta Página