locked
the handlers of the client methods (js) become multiplied RRS feed

  • Question

  • User-1020968197 posted

    I have quite strange behavior in some client instances of my application. On some computers it never happens, while on others it is quite common, using the same version of chrome.

    The server sends a message to clients (clients.all.MustUpdate) to notify them of new data. the mustUpdate function calls the server to get the new data set. That is normal behavior.

    Some computers, upon receiving the call to the javascript function mustUpdate, make not one, but several calls to the server. This is because, for some reason, some clients start duplicating the proxy callbackmap handlers.

    this is a proxy that works properly

    And this proxy duplicates the handlers, so when the server calls the MustUpdate function, it is executed as many times as handlers have been created.

    Can anyone think of why this may be happening?

    Thanks.

    Tuesday, March 9, 2021 11:24 PM

All replies

  • User-1330468790 posted

    Hi Ariel Larraburu, 

     

    Could you pleas share the js codes of binding callback functions for hub proxy?

    To target the problem, I think we should firstly try to reproduce it.

    The image tells a diiferent handler structure from my pc that a client method has been bound with multiple event handler in Array format while I don't see an array with guids.

    Apart from that, could you please also share more information:

    • Version of SignalR
    • If it is convinient, hub codes for running the test.

     

    Thank you for understanding.

    Best regards,

    Sean

    Wednesday, March 10, 2021 3:26 AM
  • User-1020968197 posted

    Hi. the signalr version is 2.4.1. I've been trying to reproduce the problem in development for a week and can't. It only happens randomly on some clients.

    this is the js code:

    'use strict';
    var sigiHub;
    var signalrStarted = false;
    var signalrLastHeartBeatLocalTime;
    var signalrLastHeartBeatRemoteTime;

    function initSignalr() {        
        signalrStarted = false;
        sigiHub = $.connection.sigiHub;
        
        sigiHub.client.mapaSitIncidentesDataAvailable = function () {        
            // irrelevant code
        };

        sigiHub.client.mapaSitIncidentesLlamadoDataAvailableByKey = function (key) {
            // irrelevant code
        };
        
        sigiHub.client.MapaSitIncidentesChangedDataAvailable = function (key, ids) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        };

        sigiHub.client.MapaSitRecursosChangedDataAvailable = function (key, ids) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        };

        sigiHub.client.MapaSitRecursosDataAvailable = function () {
            if (signalrStarted === true) {
                // irrelevant code
            }
        };

        sigiHub.client.MapaSitRecursosUbicacionDataAvailable = function () {
            if (signalrStarted === true) {
                // irrelevant code
            }
        }

        sigiHub.client.LlamadoDataAvailable = function (llamadoID, telefonoCallerID) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        }

        sigiHub.client.eliminarNotificacionLlamado = function (llamadoID) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        }

        sigiHub.client.communicationFailAddressArrival = function (incidenteID, uuid, startTime) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        }

        sigiHub.client.dismissNotification = function (id) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        }

        sigiHub.client.signalrHeartBeat = function (serverDate) {
            if (signalrStarted === true) {
                // irrelevant code
            }
        }

        hubClientStart();

        $.connection.hub.connectionSlow(function () {
            console.log('Alerta de conexión lenta');
        });

        $.connection.hub.disconnected(function () {
            setTimeout(function () {
                hubClientStart();
            }, 5000); // Reinicio a los 5 segundos de la desconeccion
            if ($.connection.hub.lastError)
            { console.log('Disconnected. Reason: ' + $.connection.hub.lastError.message); }
        });    
    }

    function hubClientStart() {    
        $.connection.hub.logging = false;
        $.connection.hub.start().done(function () {
            signalrStarted = true;
            // irrelevant code
        }).fail(function () {
            console.log('Error al conectar signalr')
            setTimeout(function () {
                hubClientStart();
            }, 5000); // Reinicio a los 5 segundos de la desconeccion
        });
    }
    ...

    Wednesday, March 10, 2021 12:20 PM