5

I'm experiencing a weird issue, where a callback using SignalR sent to multiple clients gets delayed for some of the clients.

enter image description here

As you can see there's a full 7 second delay between client A receiving the callback and client B receiving the callback.

There is a "master" client does an invoke, at the end of a timer:

                    vm.bettingconnection
                    .invoke("MoveToNextRound", gameId)
                    .catch(function (err) {
                        return console.error(err.toString());
                    });

"vm" is a VueJS object

var vm = new Vue({
el: '#gamesquares',

data: function () {
    return {
        rawgamedata: [],
        connection: "",
        bettingconnection: "",
        scorepredictShow: true,
        boardShow: false,
        timerShow: false,
        expectationShow: false,
        restseconds: 0,
        roundseconds: 0,
        restsecondsleft: 0,
        roundsecondsleft: 0,
        roundsleft: 0,
        currentround: 0,
        gamemode: 0,
        estimatedpoints: 0,
        scoreindex: 0,
        currentscore: 0,
        targetscore: 0
    };
},

The invoked endpoint has very simple logic:

        public async Task MoveToNextRound(Guid gameId)
    {
        int roundNumber = _gameAdministration.NextRound(gameId);
        //need a try catch      //game not found

        await Clients.Groups(gameId.ToString()).MovedToNextRound(roundNumber);
    }

Inside NextRound is this (also very simple)

        public int NextRound(Guid gameId)
    {
        int roundNumber = _cache.Get<int>(gameId.ToString() + "-roundnumber");
        roundNumber++;
        _cache.Set(gameId.ToString() + "-roundnumber", roundNumber);
        return roundNumber;
    }

So this bit here is where I assume the problem lies:

await Clients.Groups(gameId.ToString()).MovedToNextRound(roundNumber);

Why is that callback is taking a while to get to some of the clients?

binks
  • 1,001
  • 2
  • 10
  • 26
  • How did you confirm that the issue doesn't occur on the client? Do you see the same delay in the network tab as well? – Tasos K. Feb 20 '23 at 12:06

1 Answers1

0

There does not appear to be anything wrong with the code calling the callback. The result of the callback will be returned and then the result will be sent out to the clients within the specified group.

If all clients are on the same machine, the delay may have been due to resource contention.

If the clients are on different machines / are different kinds of clients, you may want to check the protocols that each client is using to receive messages.

In any case, you should use SignalR diagnostic logging to glean more information on exactly what's going wrong here. Details of how to do so can be found here: https://learn.microsoft.com/en-us/aspnet/core/signalr/diagnostics?view=aspnetcore-7.0

YungDeiza
  • 3,128
  • 1
  • 7
  • 32